I run a Persistent World gaming server and am trying to set up a simple script that will show it's status when I'm away from the box itself. I know the script works...because on another hoster (someone who helped write the script) it works like a charm. Here (on bluehost) I can't seem to get it to work. The code is below...again..I know it works elsewhere, and have heard that this is problem for this script on a few hosters. Anyone have advice on what I'm doing wrong that this does not work here on bluehost?
Here is what it's doing "live" if anyone wants to see for themself.
http://www.altharia.net/nwserver_status.php
Thanks for any advice.
Jeff
<?php
# function: nwserver_status
# Returns the server status in an array
# If the server does not respond with the expected hex string,
# it returns an error message (which is not an array).
function nwserver_status($serveraddr, $port="5121", $timeout=5) {
$connect = fsockopen( "udp://" . $serveraddr, $port, $errno, $errstr, $timeout );
$error = NULL;
if ( ! $connect ) {
$error = "server down";
return $error;
} else {
socket_set_timeout( $connect, $timeout );
$send = "\xFE\xFD\x00\xE0\xEB\x2D\x0E\x14\x01\x0B\x01\x05\ x08\x0A\x33\x34\x35\x13\x04\x36\x37\x38\x39\x14\x3 A\x3B\x3C\x3D\x00\x00";
fwrite( $connect, $send );
$output = fread( $connect, 5000 );
if ( ! $output ) {
$error = "no reply";
} else {
$statusarray = explode( "\x00", $output );
if (count($statusarray) < 6) { // if the array has < 6 elements, we're referencing a non-existing element
$error = "bad reply";
}
}
}
fclose( $connect );
if ($error == NULL) {
return $statusarray;
} else {
return $error;
}
}
# php script to get the server status and player list
// gets server status directly from the gameserver
$serveraddr = "altharia.dyndns.org";
// $server_down is displayed if the script can't connect
// or if it receives no data from the server
$server_down = "<p class=\"highlight\">The server is down - now what are you gonna do?</p>\n";
$status = nwserver_status($serveraddr);
if (!is_array($status)) { // if an error message was returned
print ($status);
} else {
// format serverstatus array
// $status[11] is the port used, $status[5] the number of players online
// $status[6] the maximum number of players allowed
print( "Server Address: <strong>$serveraddr:$status[11]</strong><br />\n" );
print( "Server Status: <strong>Online</strong><br />\n" );
print( "Players: <strong>$status[5]</strong> / <strong>$status[6]</strong><br />\n" );
}
?>




However, I'm perfectly happy with bluehost other than that. This was a 'nice to have' rather than a deal breaker. I do appreciate the responses.