文字

Pool::__construct

(PECL pthreads >= 2.0.0)

Pool::__construct创建新的 Worker 对象池

说明

public Pool Pool::__construct ( integer $size , string $class [, array $ctor ] )

创建新的 Worker 对象池

参数

size

此 Pool 对象可创建的 Worker 对象的最大数量

class

新创建的 Worker 对象的类

ctor

创建 Worker 对象时所用到的参数,以数组方式传入

返回值

新创建的 Pool 对象

范例

Example #1 创建 Pool 对象

<?php
class  MyWorker  extends  Worker  {
    
    public function 
__construct ( Something $something ) {
        
$this -> something  $something ;
    }
    
    public function 
run () {
        

    
}
}

$pool  = new  Pool ( 8 , \ MyWorker ::class, [new  Something ()]);

var_dump ( $pool );
?>

以上例程会输出:

object(Pool)#1 (6) {
  ["size":protected]=>
  int(8)
  ["class":protected]=>
  string(8) "MyWorker"
  ["workers":protected]=>
  NULL
  ["work":protected]=>
  NULL
  ["ctor":protected]=>
  array(1) {
    [0]=>
    object(Something)#2 (0) {
    }
  }
  ["last":protected]=>
  int(0)
}
上一篇: 下一篇: