From c829192e9ce9159eb0f46e900506f82389abfe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 8 Jun 2022 14:08:31 +0800 Subject: [PATCH] modify plugin name --- Command.php | 16 ++++++++++------ Mysql/PDO.php | 8 +++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Command.php b/Command.php index da48aeb..10035ea 100644 --- a/Command.php +++ b/Command.php @@ -140,18 +140,20 @@ class Command extends Component /** - * @param PDO $pdo * @return bool|int * @throws Exception */ - private function _execute(PDO $pdo): bool|int + private function _execute(): bool|int { try { + $pdo = $this->db->masterInstance(); + $result = $pdo->execute($this->sql, $this->params); + + $this->db->release($pdo, true); } catch (\Throwable $exception) { $result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); } finally { - $this->db->release($pdo, true); return $result; } } @@ -159,18 +161,20 @@ class Command extends Component /** * @param string $type - * @param PDO $pdo * @return array|int|bool|null * @throws Exception */ - private function search(string $type, PDO $pdo): array|int|bool|null + private function search(string $type): array|int|bool|null { try { + $pdo = $this->db->slaveInstance(); + $data = $pdo->{$type}($this->sql, $this->params); + + $this->db->release($pdo, false); } catch (\Throwable $throwable) { $data = $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql'); } finally { - $this->db->release($pdo, false); return $data; } } diff --git a/Mysql/PDO.php b/Mysql/PDO.php index caa92df..ae00edd 100644 --- a/Mysql/PDO.php +++ b/Mysql/PDO.php @@ -94,7 +94,7 @@ class PDO implements StopHeartbeatCheck public function heartbeat_check(): void { if ($this->_timer === -1) { - $this->_timer = Timer::tick(1000, fn() => $this->waite()); + $this->_timer = Timer::tick(1000, [$this, 'waite']); } } @@ -105,10 +105,8 @@ class PDO implements StopHeartbeatCheck private function waite(): void { try { - if ($this->_timer == -1) { - $this->stopHeartbeatCheck(); - } - if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) { + $tick = (int)Config::get('databases.pool.tick', 60); + if ($this->_timer == -1 || time() - $this->_last > $tick) { $this->stopHeartbeatCheck(); $this->pdo = null;