Skip to content

Commit c9ac63b

Browse files
committed
try again if caused by lost connection
1 parent 19729f1 commit c9ac63b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Illuminate/Database/SwooleMySQLConnection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Hhxsv5\LaravelS\Illuminate\Database;
44

5+
use Illuminate\Support\Str;
6+
use Illuminate\Database\QueryException;
57
use Illuminate\Database\MySqlConnection;
68

79
class SwooleMySQLConnection extends MySqlConnection
@@ -24,4 +26,15 @@ public function getDriverName()
2426
{
2527
return 'Swoole Coroutine MySQL';
2628
}
29+
30+
protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, \Closure $callback)
31+
{
32+
if ($this->causedByLostConnection($e->getPrevious()) || Str::contains($e->getMessage(), 'is closed')) {
33+
$this->reconnect();
34+
35+
return $this->runQueryCallback($query, $bindings, $callback);
36+
}
37+
38+
throw $e;
39+
}
2740
}

0 commit comments

Comments
 (0)