From bc7c5ad13b7ceff3b45bed0545c8b20abd7cf7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 2 Sep 2021 14:29:55 +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 --- core/Pool/Pool.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/Pool/Pool.php b/core/Pool/Pool.php index 6ac21216..9b1d4409 100644 --- a/core/Pool/Pool.php +++ b/core/Pool/Pool.php @@ -120,6 +120,7 @@ class Pool extends Component $channel = $this->getChannel($name); if (!$channel->isEmpty()) { $connection = $channel->pop(); + defer(fn() => $this->maxIdleQuantity($channel)); if ($this->checkCanUse($name, $connection)) { return $connection; } @@ -128,6 +129,20 @@ class Pool extends Component } + /** + * @param $channel + * @throws ConfigException + * @throws Exception + */ + private function maxIdleQuantity($channel): void + { + $minx = Config::get('databases.pool.min', 1); + if ($channel->length() > $minx) { + $this->pop($channel, $minx); + } + } + + /** * @param $name * @return bool