tryAgainIfCausedByLostConnection()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 13
rs 10
1
<?php
2
3
namespace SwooleTW\Http\Coroutine;
4
5
use Closure;
6
use Illuminate\Database\MySqlConnection as BaseConnection;
7
use Illuminate\Database\QueryException;
8
use Illuminate\Support\Str;
9
10
class MySqlConnection extends BaseConnection
11
{
12
    /**
13
     * Handle a query exception that occurred during query execution.
14
     *
15
     * @param  \Illuminate\Database\QueryException $e
16
     * @param  string $query
17
     * @param  array $bindings
18
     * @param  \Closure $callback
19
     *
20
     * @return mixed
21
     *
22
     * @throws \Illuminate\Database\QueryException
23
     */
24
    protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback)
25
    {
26
        // https://github.com/swoole/swoole-src/blob/a414e5e8fec580abb3dbd772d483e12976da708f/swoole_mysql_coro.c#L1140
27
        if ($this->causedByLostConnection($e->getPrevious()) || Str::contains(
28
                $e->getMessage(),
29
                ['is closed', 'is not established']
30
            )) {
31
            $this->reconnect();
32
33
            return $this->runQueryCallback($query, $bindings, $callback);
34
        }
35
36
        throw $e;
37
    }
38
}
39