This is a discussion on Server Detector no longer working within the PHP Language forums, part of the PHP Programming Forums category; Hi guys, I run a game server (for a game I'm writing in development). I had a routine on ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi guys,
I run a game server (for a game I'm writing in development). I had a routine on my web site which detected if the server was up or down and displayed a icon, so that people could see from the web page if the server was working or not. I just changed where my web page is hosted, and the routine no longer works, and I can't figure out why. Can anyone give me any clues? Here is the routine (taking out the IP address and port numbers) <?php if(($sock = socket_create (AF_INET, SOCK_DGRAM, 0)) < 0) { echo "socket_create() failed: reason: " . socket_strerror($sock) . "<BR>"; } else { $server='xx.xxx.xx.xx'; $port=yyyy; $send=sprintf('%c%c%c%c',24, 0, 0, 0); $x=socket_sendto($sock,$send,strlen($send)-1,0,$server,$port); $bar = array($sock); $select_result = socket_select($bar, $b=null, $c=null, 3); if ($select_result == true) { $y=socket_recvfrom($sock,&$recvbuf,1024,0,&$from,& $port); $LauncherPopulation = sprintf('%d%d%d%d%d',$recvbuf[0], $recvbuf[1], $recvbuf[2], $recvbuf[3], $recvbuf[4]); $LauncherPopulation = ltrim($LauncherPopulation, '0'); if ($LauncherPopulation == '') $LauncherPopulation = '0'; $ClientPopulation = sprintf('%d%d%d%d%d',$recvbuf[5], $recvbuf[6], $recvbuf[7], $recvbuf[8], $recvbuf[9]); $ClientPopulation = ltrim($ClientPopulation , '0'); if ($ClientPopulation == '') $ClientPopulation = '0'; echo "<CENTER>The Sovereignty Server<BR>"; echo "is UP</CENTER><BR>"; ?> <CENTER><img src="GreenGem.png" border="0"></CENTER> <?php echo "<CENTER>Launcher Population: " . $LauncherPopulation . "<BR>"; echo "Client Population: " . $ClientPopulation . "</CENTER><BR><BR>"; } else { echo "<CENTER>The Sovereignty Server<BR>"; echo "is DOWN</CENTER><BR>"; ?> <CENTER><img src="RedGem.png" border="0"></CENTER> <?php } } socket_close($sock); ?> Any ideas why this no longer works? The current result is that the page just hangs at this routine. My preliminary experiments seem to suggest that $select_result now always returns true, even when the server is off. When the server is running, the code works fine, the green gem comes up, the population values are correct. It's only when the server is NOT running that the web page locks up. $select_result is definitely returning a false positive when the server is down (which it didn't used to do before). As a result, the page is locking up at the recvfrom() line (because there is no server running to send the data from). Thanks for any advice. Ron |