From e77a66700db1df46eab0dbc5bea0291bb7a4ae2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 17 Aug 2021 19:04:44 +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 --- System/Cache/Base/Redis.php | 8 ++++++-- System/Pool/Pool.php | 4 ++-- System/Pool/StopHeartbeatCheck.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 System/Pool/StopHeartbeatCheck.php diff --git a/System/Cache/Base/Redis.php b/System/Cache/Base/Redis.php index 21cf6811..8088ceb2 100644 --- a/System/Cache/Base/Redis.php +++ b/System/Cache/Base/Redis.php @@ -6,10 +6,15 @@ use Http\Context\Context; use Kiri\Events\EventProvider; use Kiri\Exception\RedisConnectException; use Kiri\Kiri; +use Kiri\Pool\StopHeartbeatCheck; use Server\Events\OnWorkerExit; use Swoole\Timer; -class Redis + +/** + * + */ +class Redis implements StopHeartbeatCheck { const DB_ERROR_MESSAGE = 'The system is busy, please try again later.'; @@ -69,7 +74,6 @@ class Redis try { if (env('state') == 'exit') { echo 'timer end.' . PHP_EOL; - $this->stopHeartbeatCheck(); } if (time() - $this->_last > 10 * 60) { $this->stopHeartbeatCheck(); diff --git a/System/Pool/Pool.php b/System/Pool/Pool.php index 8bf82525..ad1caef2 100644 --- a/System/Pool/Pool.php +++ b/System/Pool/Pool.php @@ -53,8 +53,8 @@ class Pool extends Component } while ($channel->length() > $retain_number) { $connection = $channel->pop(); - if ($connection) { - unset($connection); + if ($connection instanceof StopHeartbeatCheck) { + $connection->stopHeartbeatCheck(); } } } diff --git a/System/Pool/StopHeartbeatCheck.php b/System/Pool/StopHeartbeatCheck.php new file mode 100644 index 00000000..44db0037 --- /dev/null +++ b/System/Pool/StopHeartbeatCheck.php @@ -0,0 +1,11 @@ +