diff --git a/src/LayerInterface.php b/src/LayerInterface.php index 1bc532a..7d4b8d0 100644 --- a/src/LayerInterface.php +++ b/src/LayerInterface.php @@ -1,6 +1,17 @@ master($sql, $params, $timeout); } + + /** + * 释放数据连接 + */ + public function clean() + { + $this->masterPool->clean(); + $this->slavePool->clean(); + } } \ No newline at end of file diff --git a/src/MySQL/Pool.php b/src/MySQL/Pool.php index ff8048a..5c784e5 100644 --- a/src/MySQL/Pool.php +++ b/src/MySQL/Pool.php @@ -51,7 +51,7 @@ public function get() : Item $item = $this->pool->pop($this->timeout); if ($item === false) { - throw new Exception('Get Item instance timeout, all connection is used!'); + throw new Exception('Get mysql connection instance timeout, pool: ' . $this->getLength()); } return $item; @@ -64,4 +64,14 @@ public function getLength() : int { return $this->pool->length(); } + + /** + * 清空数据库连接池(释放数据连接) + */ + public function clean() + { + while ($item = $this->pool->pop($this->timeout)) { + $item->close(); + } + } } diff --git a/src/PoolInterface.php b/src/PoolInterface.php index ef75edf..66cb47f 100644 --- a/src/PoolInterface.php +++ b/src/PoolInterface.php @@ -1,7 +1,6 @@ slavePool->put($item); } + + /** + * 释放数据连接 + */ + public function clean() + { + $this->masterPool->clean(); + $this->slavePool->clean(); + } } diff --git a/src/Redis/Pool.php b/src/Redis/Pool.php index 23ee49b..f7d6591 100644 --- a/src/Redis/Pool.php +++ b/src/Redis/Pool.php @@ -51,7 +51,7 @@ public function get() $item = $this->pool->pop($this->timeout); if ($item === false) { - throw new Exception('Get Item instance timeout, all connection is used!'); + throw new Exception('Get redis connection instance timeout, pool: ' . $this->getLength()); } return $item; @@ -64,4 +64,14 @@ public function getLength() : int { return $this->pool->length(); } + + /** + * 清空数据库连接池(释放数据连接) + */ + public function clean() + { + while ($item = $this->pool->pop($this->timeout)) { + $item->close(); + } + } }