Server Detector no longer working

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-10-2004
RonHiler
 
Posts: n/a
Default Server Detector no longer working

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0