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

stream_select / timeoutexception #261

Closed CodingDK closed 8 years ago

CodingDK commented 9 years ago

If I make a php script (cronjob) for pinging a CS Source server with: echo $server->getPing().

It make a timeoutexception. The most strange is that the script has worked fine for several days, but now it has started with this error

Output is:

Notice: Sending packet of type "A2S_INFO_Packet"... in /var/www/site.com/lib/steam/sockets/SteamSocket.php on line 142
Warning: stream_select() [function.stream-select]: You MUST recompile PHP with a larger value of FD_SETSIZE. It is set to 1024, but you have descriptors numbered at least as high as 2111. --enable-fd-setsize=3072 is recommended, but you may want to set it to equal the maximum number of open files supported by your system, in order to avoid seeing this error again at a later date. in /var/www/site.com/lib/Socket.php on line 155
exception 'TimeoutException' with message 'The operation timed out.' in /var/www/site.com/lib/steam/sockets/SteamSocket.php:108 Stack trace:

0 /var/www/site.com/lib/steam/sockets/SourceSocket.php(36): SteamSocket->receivePacket(1400)

1 /var/www/site.com/lib/steam/servers/GameServer.php(260): SourceSocket->getReply()

2 /var/www/site.com/lib/steam/servers/GameServer.php(397): GameServer->getReply()

3 /var/www/site.com/lib/steam/servers/GameServer.php(167): GameServer->updatePing()

4 /var/www/site.com/cssPing.php(7): GameServer->getPing()

5 {main}

koraktor commented 9 years ago

Looks like it's leaking file descriptors. Restarting should fix this temporarily.

I'll have a look at the code, to see where this is originating from.

koraktor commented 9 years ago

I could not find a possible reason for this. Sockets and their file descriptors should be automatically closed once they are destructed. In a cronjob this should happen right after execution.

Can you install the sockets PHP extension on your server? Would be interesting to see if it happens with that, too. Can you provide some of your code? Does this occur more often when you execute the cronjob in shorter intervals?

CodingDK commented 9 years ago

My host is a cheap one (unoeuro), unfortunately I do not have the option of installing PHP extensens.

My code (this is the simple prototype, but if you want the 500 linies cronjob code, just say it):

<?php
require_once '../lib/steam-condenser.php';
try {
    $server = new SourceServer('ip', 'port');

    echo $server->getPing();
}
catch (Exception $e) {
    echo $e;
}
?>

My cronjobs task was pinging our css server, every 3-4 minutes, and if there was no response 4 times in a row, it should log into our css hosts controlpanel and restart CSS server. And because of the TimeoutException, the job also will restart the css server, so right now i dont want to use it anyway.

I have just written to my host in order to get them to restart the web server.

koraktor commented 9 years ago

It seems that this warning is a problem of stream_select(). Can you try to modify the file Socket.php at line 155 to:

            $select = @stream_select($read, $write, $except, $sec, $usec);

This seems to be a warning and can be simple skipped by adding the @. Nevertheless it hints at dangling open sockets.

CodingDK commented 9 years ago

The warning is gone now, but it still make the TimeoutException. I have tryed several servers.

koraktor commented 9 years ago

Can you provide one of the IPs you're trying to ping. I'll try to reproduce this.

CodingDK commented 9 years ago

46.174.49.21:27260

koraktor commented 9 years ago

The timeouts are not related to the warning. I could reproduce them multiple times without getting the warning once. You should probably adapt your script to handle sporadic timeouts more gracefully.

CodingDK commented 9 years ago

The problem is that it makes timeoutException all the time right now, even with the script I posted above

koraktor commented 9 years ago

I'm sorry. It seems I'm unable to reproduce this issue. How long does it take from a working script to the warnings above and the permanent timeouts afterwards? Minutes, hours, days?

Had a test script (and without the sockets extension) running for a few hours without any problem.

I fear this is some host specific problem that cannot be fixed codewise.