We have several servers that I would like to set up a webpage for that displays them all in a neat little table and puts up a red or a green dot depending on if they are currently up or down. I have been playing around with fsockopen() and that works for some of the servers but for others I get a timeout error. However, I can ping all of them fine from the command line. So after searching through some similar posts here I am wondering if somebody could give me a bit of help.
This is the code I've been trying to use to open the sockets and check for a connection:
<?
function IsAlive($hostname, $portname){
$host = $hostname;
$port = $portname;
$sk = fsockopen("$host", $port, $ernno, $errstr, 3);
if (!$sk) {
?><center><img src="/images/red.gif"></center><?php
} else {
?><center><img src="/images/green.gif"></center><?php
fclose($sk);
}
}
?>
Now, the script works in that I get a red or green dot to be displayed. However, there are two problems. When I get a timeout, all of the error msgs are displayed as well (which I dont want to show up, I just want the button to show up) AND some servers that ARE up and that I CAN ping return as timed out.
Should I dump this code and try to just ping the servers for a response, and if so, where should I start?
Thanks.