qqq
This commit is contained in:
+24
-5
@@ -84,7 +84,7 @@ class Command extends Component
|
|||||||
$prepare->execute($this->params);
|
$prepare->execute($this->params);
|
||||||
return $prepare->fetchAll(PDO::FETCH_ASSOC);
|
return $prepare->fetchAll(PDO::FETCH_ASSOC);
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if ($this->canReconnect($throwable->getMessage())) {
|
||||||
return $this->all();
|
return $this->all();
|
||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
@@ -107,7 +107,7 @@ class Command extends Component
|
|||||||
$prepare->execute($this->params);
|
$prepare->execute($this->params);
|
||||||
return $prepare->fetch(PDO::FETCH_ASSOC);
|
return $prepare->fetch(PDO::FETCH_ASSOC);
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if ($this->canReconnect($throwable->getMessage())) {
|
||||||
return $this->one();
|
return $this->one();
|
||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
@@ -130,7 +130,7 @@ class Command extends Component
|
|||||||
$prepare->execute($this->params);
|
$prepare->execute($this->params);
|
||||||
return $prepare->fetchColumn(PDO::FETCH_ASSOC);
|
return $prepare->fetchColumn(PDO::FETCH_ASSOC);
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if ($this->canReconnect($throwable->getMessage())) {
|
||||||
return $this->fetchColumn();
|
return $this->fetchColumn();
|
||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
@@ -153,7 +153,7 @@ class Command extends Component
|
|||||||
$prepare->execute($this->params);
|
$prepare->execute($this->params);
|
||||||
return $prepare->rowCount();
|
return $prepare->rowCount();
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if ($this->canReconnect($throwable->getMessage())) {
|
||||||
return $this->rowCount();
|
return $this->rowCount();
|
||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
@@ -195,7 +195,7 @@ class Command extends Component
|
|||||||
}
|
}
|
||||||
return $result == 0 ? true : (int)$result;
|
return $result == 0 ? true : (int)$result;
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if ($this->canReconnect($throwable->getMessage())) {
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
@@ -203,6 +203,25 @@ class Command extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function canReconnect(string $message): bool
|
||||||
|
{
|
||||||
|
$errors = [
|
||||||
|
'MySQL server has gone away',
|
||||||
|
'Packets out of order. Expected 1 received 0.'
|
||||||
|
];
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
if (str_contains($message, $error)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Throwable $throwable
|
* @param Throwable $throwable
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
Reference in New Issue
Block a user