I have a java-based chat service and I use a bit of php code to display the current number of chatters on my main splash page. We had an incident this morning where the java chat did not start up properly after a server reboot, and the result was that this bit of php code blared a huge error message across the page. How can I change this php code to suppress the warning/error message?
PHP Code:
Currently there are:<br><span style="font-weight: bold; font-size: 26px;">
<?
$port = 1####;
function getServerAPI( $apiCommand ) {
global $port;
$result = "";
$fp = fsockopen("localhost", $port, &$errno, &$errstr, 2);
if(!$fp) {
echo "<!-- $errstr ($errno) -->\n";
} else {
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
$header = true;
while(!feof($fp)) {
$line = fgets($fp,128);
if ( $header hahahaha false ) $result .= $line;
if ( trim($line) hahahaha "" ) $header = false;
}
fclose($fp);
}
return $result;
}
$userCount = getServerAPI( "api.UserCount" );
$roomList = getServerAPI( "api.RoomList" );
if ($userCount < 4) { $userCount = 4; }
echo $userCount;
?>
</span><br>members chatting
The problem is the line
PHP Code:
$fp = fsockopen("localhost", $port, &$errno, &$errstr, 2);
If the chat is down it displays a warning message that the fsockopen failed. How can I suppress that warning message without any complicated server or php-setting changes?
Thanks in adance for any help.