Skip to content

Commit

Permalink
新增周期检测
Browse files Browse the repository at this point in the history
  • Loading branch information
yf committed Nov 6, 2018
1 parent e8ab0f9 commit a54f893
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Pool/PoolManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ class PoolManager

private $pool = [];

/**
* @param string $className
* @param int $maxNum
* @return bool
* @throws \Throwable
*/
function register(string $className, $maxNum = 20):bool

function register(string $className, $maxNum = 20,$intervalCheckTime = 30*1000,$idleGCTime = 15):bool
{
$ref = new \ReflectionClass($className);
if($ref->isSubclassOf(AbstractPool::class)){
$this->pool[$this->generateKey($className)] = [$className,$maxNum];
$this->pool[$this->generateKey($className)] = [$className,$maxNum,$intervalCheckTime,$idleGCTime];
return true;
}else{
return false;
Expand All @@ -41,9 +36,9 @@ function getPool(string $className):?AbstractPool
{
$key = $this->generateKey($className);
if(isset($this->pool[$key]) && is_array($this->pool[$key])){
$className = $this->pool[$key][0];
$max = $this->pool[$key][1];
$obj = new $className($max);
$args = $this->pool[$key];
$className = array_shift($args);
$obj = new $className(...$args);
$this->pool[$key] = $obj;
return $obj;
}else if(isset($this->pool[$key])){
Expand Down

0 comments on commit a54f893

Please sign in to comment.