Ratchet
Ratchet copied to clipboard
Websocket ratchet server stop after a while and gives warning
The warning: PHP Warning: Error while sending QUERY packet Note:There was no activity on the website
Hi, I think your problem is related to the maximum waiting time of your database (I guess it's MySQL :) You can try increasing the wait_timeout for the database, but this is not an eternal solution, as it has a maximum wait time limit. For solve this problem I reconnect to my DB every minute(depends on your settings), sample code:
use App\Models\Message;
use Ratchet\App;
use React\EventLoop\Factory;
$loop = Factory::create();
$server = new App('localhost', 8080, '0.0.0.0', $loop);
$server->route('/chat', new Chat, ['*']);
$loop->addPeriodicTimer(60, function() use ($DB) {
$DB->reconnect(); // For example, change to your reconnection logic
});
$server->run();
Are you using https://github.com/friends-of-reactphp/mysql to connect with the database?
I think I'm having a similar issue. Could I get a short explanation of why the alternate mysql connector is recommended?
@nivshah Well in short, the build in Database connectors in PHP don't support non-blocking, the connector I linked is created specifically to support doing MySQL queries in non-blocking environments like Ratchet