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

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).

Resolved.

I contacted my hosting company and got the following:

Tyler!

Thanks for contacting us.

Your script took about 10s to run, but it did run:

[/root]# time php -q -f /tmp/nanno

   <table>
           <thead>
                   <td>Minecraft Server Status</td>
           </thead>
           <tr>
                   <td>Server 1: 70.89.xxx.226:25565</td>
                   <td>DOWN</td>
           </tr>
           <tr>
                   <td>Server 2: 50.22.xxx.147:25591</td>
                   <td>DOWN</td>
           </tr>
   </table> real    0m10.071s user    0m0.047s sys     0m0.019s

And bad news, your servers are down. However, this part of your script is fine ;) ... and I do get: Minecraft Server Status Server 1: 70.89.xxx.226:25565 DOWN Server 2: 50.22.36.xxx:25591 DOWN on

(so it looks like your browser or http connection is timing out on your end). Unless you know of a way of adjusting your script to lower a timeout variable, your browser network timeout setting, or perhaps if you were to run both fsocks simultaneously you would have the run time?

Let us know if you have any further questions or concerns.

Regards,

------ Robert C. Server Analyst II SurpassHosting.com, LLC http://www.surpasshosting.com http://www.surmunity.com


ME: Thanks for the prompt reply!

Well it took ten seconds because there are two connection attempts with 5 second timeouts.

The problem is that they should NOT be timing out, I'm in the server right now, and my local server can connect with fsockopen no problem and will display them as UP.

What I don't understand is why my script can't 'see' my game servers from my web server.

Thanks for your time, TylerT


Them: Hello Tyler ,

The issue is fixed you can view the status now .

Thanks

Regards, Praveen M Senior Unix Admin SurpassHosting.com, LLC http://www.surpasshosting.com http://www.surmunity.com

I dunno if they'll tell me what the problem was, I am very curious. LOL at the first response though.