drcb19700 2011-03-25 03:48
浏览 86

PHP fsockopen():本地测试服务器与远程服务器

I'm hoping there is a quirk about apache/php that I'm missing.

The Code:

<?php
    $servers = array(
        array("70.89.xxx.226",25565,''),
        array("50.22.xxx.147",25591,''),
    );

    foreach($servers as $key=>$server){
        $fp = @fsockopen($server[0],$server[1],$errno,$errstr,.5);
        if(!$fp) {
            $servers[$key][2] = "DOWN";
        } else {
            $servers[$key][2] = "UP";
            @fclose($fp);
        }
        unset($fp);
    }


    echo"
    <table>
        <thead>
            <td>Minecraft Server Status</td>
        </thead>";

    foreach ($servers as $key=>$server){
        $keyplus = $key + 1;
        echo"
        <tr>
            <td>Server $keyplus: $server[0]:$server[1]</td>
            <td>$server[2]</td>
        </tr>";
    }

    echo "
    </table>";
    ?>

What it does: check connectivity to a variety of minecraft servers with the fsockopen function.

The problem: This code does exactly what it's supposed to do on both my local and my remote web servers. However, on my remote server, the status always displays as DOWN even when I know they are UP, they also display as UP on my local server. I can't figure out WHY my host wouldn't be able to reach these servers, so I hope its a server quirk i don't know about.

How you can help: Maybe theres another way to effectively ping an IP in php that I could use? or maybe you know of a server setting that is effecting my connectivity.

thank for reading and your time ~TylerTofWA

  • 写回答

2条回答 默认 最新

  • dongmei2957 2011-03-25 03:55
    关注

    Remove the @ on fsockopen to stop suppressing errors to see if there are errors being thrown on your remote server. Also make sure error_reporting is set to show all errors using error_reporting(A_ALL).

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题