From 89bd7a8ee93813564e6bef3e89c1f6b540ef3900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 6 Dec 2021 15:39:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mysql/PDO.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Mysql/PDO.php b/src/Mysql/PDO.php index d352971..b01ae6f 100644 --- a/src/Mysql/PDO.php +++ b/src/Mysql/PDO.php @@ -4,7 +4,6 @@ namespace Database\Mysql; use Exception; use Kiri\Abstracts\Logger; -use Kiri\Context; use Kiri\Kiri; use Kiri\Pool\StopHeartbeatCheck; use PDOStatement; @@ -67,21 +66,28 @@ class PDO implements StopHeartbeatCheck if (env('state', 'start') == 'exit') { return; } - if ($this->_timer === -1 && Context::inCoroutine()) { - $this->_timer = Timer::tick(1000, function () { - try { - if (env('state', 'start') == 'exit') { - Kiri::getDi()->get(Logger::class)->critical('timer end'); - $this->stopHeartbeatCheck(); - } - if (time() - $this->_last > 10 * 60) { - $this->stopHeartbeatCheck(); - $this->pdo = null; - } - } catch (\Throwable $throwable) { - error($throwable); - } - }); + if ($this->_timer === -1) { + $this->_timer = Timer::tick(1000, fn() => $this->waite()); + } + } + + + /** + * @throws Exception + */ + private function waite(): void + { + try { + if (env('state', 'start') == 'exit') { + Kiri::getDi()->get(Logger::class)->critical('timer end'); + $this->stopHeartbeatCheck(); + } + if (time() - $this->_last > 10 * 60) { + $this->stopHeartbeatCheck(); + $this->pdo = null; + } + } catch (\Throwable $throwable) { + error($throwable); } }