From e5c5ce822c89f121e71adcf719fdeccf41982f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 16 Aug 2023 12:19:47 +0800 Subject: [PATCH] qqq --- Connection.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Connection.php b/Connection.php index df6b574..5e3fe2d 100644 --- a/Connection.php +++ b/Connection.php @@ -150,13 +150,8 @@ class Connection extends Component { /** @var PDO $client */ $client = $this->pool()->get($this->cds); - try { - if (($steam = $client->query('select 1')) !== false) { - return $client; - } - $this->logger->error($steam->errorInfo()[1]); - } catch (\Throwable $exception) { - $this->logger->error($exception); + if ($this->canUse($client)) { + return $client; } Waite::sleep(10); 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 * @throws Exception