-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
MySQL server has gone away - how to deal with it #4131
Comments
try to set max_execution_time = 0 in php.ini |
|
Try to reconnect to the database. for ($i = 0; $i < 2; $i++) {
$result = $db->query($sql);
if ($result === false) {
if ($db->errno == 2013 or $db->errno == 2006 or ($db->errno == 0 and !$db->ping())) {
$db = $dbpool->get();
if ($r === true) {
continue;
}
} else {
return false;
}
}
break;
} |
The best way to deal with this is having Just add following to the ->withOptions([
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
]) This will still throw exceptions, but after the proxy classes have done its work 👍🏻 @matyhtf This should probably be part of the documentation or set by default, otherwise if the exception is thrown here the remaining code is never reached. |
I'm trying to use Swoole as a API server. At the moment it works great but has one issue that I can't find workaround for. Basically I have DB connection through PDO to the MariaDB and some stuff that works with data.
This is simplified code that I'm playing with:
Properly working code, with working DB connection. ;) I think
ConnectionPool
should have some way to auto reconnect if connection is dead. I tried to do something about that but I couldn't get it to work as I intended:Unfortunetly PDO doesn't have built-in way to detect connection status. No ping or anything like that. At least nothing I'm aware of. :(
I'm still testing the code above to find a way to reconnect on failed connection.
If I leave Swoole running along with MariaDB and there won't be enough connections during that time, MariaDB will timeout connections from connection pool with no mean to reconnect, with one of the errors:
and Swoole outputs:
php --ri swoole
)?uname -a
&php -v
&gcc -v
) ?The text was updated successfully, but these errors were encountered: