This commit is contained in:
2023-08-16 12:19:47 +08:00
parent 68035a95e4
commit e5c5ce822c
+23 -6
View File
@@ -150,14 +150,9 @@ class Connection extends Component
{ {
/** @var PDO $client */ /** @var PDO $client */
$client = $this->pool()->get($this->cds); $client = $this->pool()->get($this->cds);
try { if ($this->canUse($client)) {
if (($steam = $client->query('select 1')) !== false) {
return $client; return $client;
} }
$this->logger->error($steam->errorInfo()[1]);
} catch (\Throwable $exception) {
$this->logger->error($exception);
}
Waite::sleep(10); Waite::sleep(10);
return $this->checkClientHealth(); return $this->checkClientHealth();
} }
@@ -181,6 +176,28 @@ class Connection extends Component
} }
/**
* @param PDO|null $client
* @return bool
*/
protected function canUse(?PDO $client): bool
{
if (is_null($client)) {
return false;
}
try {
$steam = $client->query('select 1');
if ($steam !== false) {
return true;
}
return false;
} catch (\Throwable $exception) {
$this->logger->error($exception);
return false;
}
}
/** /**
* @return PDO * @return PDO
* @throws Exception * @throws Exception