minecraft-server-status icon indicating copy to clipboard operation
minecraft-server-status copied to clipboard

the value of online appears to always be 1 when using query

Open codahq opened this issue 2 years ago • 2 comments

i'm looping through an array of servers to check the status of each and then i build a page. when a server is online the object contains all of the fields the server offers.

when a server is offline the object still contains an empty field with the value NULL, a software field with the value "Vanilla", and an online field with a value of int(1). regardless of the server status when using query it appears the server is always online == 1.

codahq avatar Mar 29 '23 05:03 codahq

Can you provide a snippet of your code where the incorrect result occurs?

noxifoxi avatar Mar 29 '23 21:03 noxifoxi

Sure.

for ($x = 0; $x < $arrlength; $x++) {
        try {
          include_once 'MinecraftServer.php';
          $server = new MinecraftServer($servers[$x]->qhost, $servers[$x]->qport, 1);
        } catch (Exception $e) {     }

        //var_dump($server->getInfoArray());
        $online = $server && $server->online == 1 && $server->hostname;

        //generating some html here
}

There's an array of arrays ($servers) that hold the server values. Every check returns a value of online == 1 so I simply added a check for the hostname which was only populated when a server was really online. I've worked around it but I'm reporting the issue so you can fix the underlying cause if you want.

Also, as a side note, I don't know if the library or vanilla php supports more granular timeouts but the minimum 1 second is a really long time when checking local servers. I would prefer to fail out at 50ms or even 25ms so that the page can load faster. The response when the server is up will always come back in less than 1ms and never come back if it's down. Just throwing that out there in case you improve the library.

codahq avatar Mar 31 '23 16:03 codahq