Jump to content

Can't get rid of fsockopen error in server status script


Eiolon

Recommended Posts

I am working on a server status script using fsockopen.  When the server is online, it displays online fine.  However, when it is offline, it lists the server offline but gives me an fosckopen error.  How do I make it so the PHP error is not shown and just the offline is shown?

 

<?php 

function server_check ($hport,$hdomain) {
$fp = fsockopen($hdomain, $hport, $errno, $errstr, 4);
if (!$fp){
	$data = "<font color=red>OFFLINE</font>";
         } else {
	$data = "<font color=green>ONLINE</font>";
	fclose($fp);
}
return $data;
}
?>

<?php

echo "<table width=200 border=0 cellspacing=1 cellpadding=6 bgcolor=#CCCCCC>";
echo "<tr bgcolor=#E5E5E5><td width=100><strong>Service</strong></td>";
echo "<td width=100><div align=center><strong>Status</strong></div></td></tr>";
echo "<tr bgcolor=#FFFFFF><td width=100>Polaris</td>";
echo "<td width=100><div align=center>".server_check("3389","192.168.19.42")."</div></td></tr>";
echo "<tr bgcolor=#FFFFFF><td width=100>SIP</td>";
echo "<td width=100><div align=center>".server_check("5000","192.168.19.31")."</div></td></tr></table>";

?>

 

Here is the error that is being shown:

 

Warning: fsockopen() [function.fsockopen]: unable to connect to 192.168.19.31:5000 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\wamp\www\includes\functions.php on line 16

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.