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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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