Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
codahq opened this issue Mar 29, 2023 · 2 comments
Open

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

codahq opened this issue Mar 29, 2023 · 2 comments

Comments

@codahq
Copy link

codahq commented Mar 29, 2023

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.

@noxifoxi
Copy link
Owner

noxifoxi commented Mar 29, 2023

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

@codahq
Copy link
Author

codahq commented Mar 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants