Php code players online

Discussion in 'Bukkit Help' started by matthiasvd2, Dec 24, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    matthiasvd2

    Hey i got this php code:

    Code:
    <?php
    /* Minecraft 1.4+ server list ping script
     
     
    For usage and distribution information, see: http://www.gnu.org/licenses/lgpl-3.0.html */
     
    $host = "83.82.235.30"; //IP/host of Minecraft server
    $port = 25565; //Minecraft server port, not query port
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //Create the socket
    $connected = socket_connect($socket, $host, $port); //Try and connect using the info provided above
     
    if (!$connected)
        die("Could not connect to server."); //No connection could be established
     
    socket_send($socket, "\xFE\x01", 2, 0); //Send the server list ping request (two bytes)
    $retVal = socket_recv($socket, &$data, 1024, 0); //Get the info and store it in $data
    socket_close($socket); //Close socket
     
    if ($retVal != false && substr($data, 0, 1) == "\xFF") //Ensure we're getting a kick message as expected
    {
        $data = substr($data, 9); //Remove packet, length and starting characters
        $data = explode("\x00\x00", $data); //0000 separated info
        $protocolVersion = $data[0]; //Get it all into separate variables
        $serverVersion = $data[1];
        $motd = $data[2];
        $playersOnline = $data[3];
        $playersMax = $data[4];
    }
    else
    {
        die("Can't ping to the server"); //Either retVal was false or we didn't get a kick message
    }
     
    //Example usage:
    echo ("Version: $serverVersion Players online: $playersOnline/$playersMax");
    ?>
    But when he can't ping to the server the hole webpage stop with loading :s

    Does someone now why and how it can be fixed?
     
  2. Need to ask the owner of the code.
     
  3. Offline

    rustymetal

    the socket_connect has no timeout option. Resulting in a page that never loads because it can't connect.

    Have the author use fsocketopen or set_socket_options, or possbily socket_set_noblock that does not interrupt the script and returns a false if it cant connect.
     
Thread Status:
Not open for further replies.

Share This Page