Results 1 to 4 of 4

Thread: PHP Server Status Script

  1. #1
    Join Date
    Jul 2006
    Posts
    2

    Default PHP Server Status Script

    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" );
    }

    ?>

  2. #2
    Join Date
    Jun 2006
    Posts
    7

    Default

    I think your problem might the fact that you are trying to use fsockopen with a port other than 80, but I might be mistaken.
    Drop a mail to support to make sure.

  3. #3
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    153

    Default

    Quote Originally Posted by death2all
    I think your problem might the fact that you are trying to use fsockopen with a port other than 80, but I might be mistaken.
    Drop a mail to support to make sure.
    Yes, unless you have a dedicated IP any requests to all ports except a few (such as 80) will be blocked. If you wish to establish a connection to other ports you will need to purchase a dedicated IP.

    http://helpdesk.bluehost.com/kb/inde...root=17&id=174
    BlueHost Knowledge Base, it is quite helpful, you should read through it.

  4. #4
    Join Date
    Jul 2006
    Posts
    2

    Default

    Much thanks. I have to wonder about that policy. Since many other hosters don't seem to have that problem with this script. 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.

    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •