Ratchet icon indicating copy to clipboard operation
Ratchet copied to clipboard

Websocket ratchet server stop after a while and gives warning

Open ahmedelsied opened this issue 4 years ago • 4 comments

The warning: PHP Warning: Error while sending QUERY packet Note:There was no activity on the website

ahmedelsied avatar Nov 01 '20 09:11 ahmedelsied

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();

ararati avatar Feb 05 '21 08:02 ararati

Are you using https://github.com/friends-of-reactphp/mysql to connect with the database?

WyriHaximus avatar Feb 05 '21 08:02 WyriHaximus

I think I'm having a similar issue. Could I get a short explanation of why the alternate mysql connector is recommended?

nivshah avatar Mar 28 '21 23:03 nivshah

@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

WyriHaximus avatar Apr 04 '21 07:04 WyriHaximus