koraktor / steam-condenser

A multi-language library for querying the Steam Community, Source, GoldSrc servers and Steam master servers
https://koraktor.de/steam-condenser
Other
356 stars 67 forks source link

How to check the status of the server? #267

Closed afuno closed 9 years ago

afuno commented 9 years ago

Hello.

How to check the status of the server? For example, when it is off. In the test directory are many examples, but I did not understand anything in them.

Can you please give an example without being tied to any framework?

koraktor commented 9 years ago

Checking the availability of a server can be done with the #getPing() or #getServer() methods and checking for timeouts.

If you have questions on the usage please ask on Gitter or in the Google group.

afuno commented 9 years ago

A string var_dump($server->getPing()); displays an error:

Warning: socket_read(): unable to read from socket [111]: Connection refused in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php on line 119 Fatal error: Uncaught exception 'Vendor\Classes\SteamCondenser\Exceptions\SocketException' with message 'Connection refused (Code: 111)' in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php:127 Stack trace: #0 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/Sockets/SteamSocket.php(130): Vendor\Classes\SteamCondenser\Socket->recv(1400) #1 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/Sockets/SourceSocket.php(59): Vendor\Classes\SteamCondenser\Servers\Sockets\SteamSocket->receivePacket(1400) #2 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(276): Vendor\Classes\SteamCondenser\Servers\Sockets\SourceSocket->getReply() #3 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(413): Vendor\Classes\SteamCondenser\Servers\GameServer->getReply() #4 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(183): Vendor\Classes\SteamCondenser\Servers\GameServer->upd in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php on line 127

koraktor commented 9 years ago

This basically means "there is no server listening at the specified IP and port", so the server is down.

afuno commented 9 years ago

Well, how do I handle this error?

try catch me does not help...

koraktor commented 9 years ago

catch (SteamCondenser\Exceptions\SocketException) should serve you well.

afuno commented 9 years ago

No, friend, is not obtained. Or I do not understand something, or something else...

try { var_dump($server->getPing()); } catch (Vendor\Classes\SteamCondenser\Exceptions\SocketException $e) { var_dump($e->getMessage()); }

Displays the error: Warning: socket_read(): unable to read from socket [111]: Connection refused in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php on line 119 Fatal error: Uncaught exception 'Vendor\Classes\SteamCondenser\Exceptions\SocketException' with message 'Connection refused (Code: 111)' in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php:127 Stack trace: #0 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/Sockets/SteamSocket.php(130): Vendor\Classes\SteamCondenser\Socket->recv(1400) #1 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/Sockets/SourceSocket.php(59): Vendor\Classes\SteamCondenser\Servers\Sockets\SteamSocket->receivePacket(1400) #2 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(276): Vendor\Classes\SteamCondenser\Servers\Sockets\SourceSocket->getReply() #3 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(413): Vendor\Classes\SteamCondenser\Servers\GameServer->getReply() #4 /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Servers/GameServer.php(183): Vendor\Classes\SteamCondenser\Servers\GameServer->upd in /var/www/username/data/www/site.com/Vendor/Classes/SteamCondenser/Socket.php on line 127

afuno commented 9 years ago

var_dump($server->getPing()); displays the error. var_dump($e->getMessage()); does not display anything.

koraktor commented 9 years ago

The warning can be suppressed by different means, most easily by setting error_reporting(). Once you catch the correct exception (try only Exception to catch all), you should have no problem to get its message (or error code).

Please do not use this issue for basic PHP programming questions.