Hi guys,
Recently moved into PHP for a personal application. Basically, it tries to connect some servers to see if they're online. It ultimately returns a string, which the caller echos. The main function is:
function IsServerOnline($IP, $checkforevent = TRUE, $ischannel = TRUE, $PORT = 11020)
{
global $UseGlobalOverride, $UseChannelOverride, $GlobalOverride, $ChannelOverride, $UseOfflineOverride, $OfflineOverride, $IsEvent;
if ($UseGlobalOverride) return $GlobalOverride;
if ($UseChannelOverride && $ischannel) return $ChannelOverride;
$fp = fsockopen($IP, $PORT, &$errnum, &$errstr , 2);
if (!$fp)
{
if ($UseOfflineOverride) return $OfflineOverride; else return "offline";
}
else
{
fclose($fp);
if ($checkforevent && $IsEvent) return "event"; else return "online";
}
}
and it is called by this:
|Server1=<?php echo(IsServerOnline("208.85.108.17", TRUE, TRUE, 80)); ?><br>
|Server2=<?php echo(IsServerOnline("63.251.217.212", FALSE, FALSE, 80)); ?><br>
|Server3=<?php echo(IsServerOnline("208.85.108.15", FALSE, FALSE, 11000)); ?><br>
It all works wonderfully, except when a server goes down. Then, the "timeouts" kick in, and the page gets slow to load. I have approximately 50 servers to test, so this webpage gets very slow at times. What would be my best bet for running the tests asynchronously and then printing the correct output in the correct place?