From b9dacda690a67680644777590558e631e871d3d6 Mon Sep 17 00:00:00 2001 From: yf <29323003@qq.com> Date: Fri, 30 Nov 2018 08:57:01 +0800 Subject: [PATCH] fix bug --- src/Pool/AbstractPool.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Pool/AbstractPool.php b/src/Pool/AbstractPool.php index 7fa66d3..196f51b 100644 --- a/src/Pool/AbstractPool.php +++ b/src/Pool/AbstractPool.php @@ -60,14 +60,20 @@ public function recycleObj($obj):bool } } - public function getObj(float $timeout = 0.1) + public function getObj(float $timeout = 0.1,int $tryTimes = 3) { + if($tryTimes <= 0){ + return null; + } //懒惰创建模式 $obj = null; if($this->chan->isEmpty()){ //如果还没有达到最大连接数,则尝试进行创建 if($this->createdNum < $this->max){ $this->createdNum++; + /* + * 创建对象的时候,请加try,尽量不要抛出异常 + */ $obj = $this->createObject(); if(!is_object($obj)){ $this->createdNum--; @@ -96,7 +102,7 @@ public function getObj(float $timeout = 0.1) if($status == false){ $this->unsetObj($obj); //重新进入对象获取 - return $this->getObj($timeout); + return $this->getObj($timeout,$tryTimes - 1); } } return $obj;