From fb851bbfc1bddbb126056ba808caacd4fb7db461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 3 Apr 2023 00:14:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Pool/Connection.php | 8 +++++++- kiri-engine/Pool/Pool.php | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/kiri-engine/Pool/Connection.php b/kiri-engine/Pool/Connection.php index 263f9e20..69bd8f0f 100644 --- a/kiri-engine/Pool/Connection.php +++ b/kiri-engine/Pool/Connection.php @@ -25,6 +25,8 @@ class Connection extends Component private array $master = []; + private int $total = 0; + /** * @param Pool $pool @@ -150,7 +152,11 @@ class Connection extends Component */ public function create($config): Closure { - return static function () use ($config) { + return function () use ($config) { + if ($this->total >= 300) { + return $this->pool->waite($config['cds'], 30); + } + $this->total += 1; return new \Database\Mysql\PDO($config); }; } diff --git a/kiri-engine/Pool/Pool.php b/kiri-engine/Pool/Pool.php index e2810563..6f7f3908 100644 --- a/kiri-engine/Pool/Pool.php +++ b/kiri-engine/Pool/Pool.php @@ -243,6 +243,19 @@ class Pool extends Component } + /** + * @param $name + * @param int $time + * @return array + * @throws ConfigException + */ + public function waite($name, int $time = 30): mixed + { + return $this->channel($name)->pop($time); + } + + + /** * @param string $name * @throws Exception