Level 27
I used this to deal with the problem, if there is a better way, please let me know. Thank you.
// v1
try {
...
} catch (\Exception $e) {
if (Str::of($e->getMessage())->contains('MySQL server has gone away')) {
DB::reconnect();
...
}
// v2
use Illuminate\Database\DetectsLostConnections;
...
try {
...
} catch (\Exception $e) {
if ($this->causedByLostConnection($e)) {
DB::reconnect();
...
}
1 like