pthreads Pool::__construct

(PECL pthreads >= 2.0.0)

Pool::__construct — 새로운 Workers 풀 생성


설명

public Pool::__construct(int $size, string $class = ?, array $ctor = ?)

새로운 Worker 풀을 구성합니다. 풀은 스레드를 느리게 생성합니다. 즉, 새 스레드는 작업을 실행해야 할 때만 생성됩니다.


매개변수

size
이 풀이 생성할 수 있는 최대 작업자 수
class
새 Worker을 위한 클래스입니다. 클래스가 제공되지 않으면 기본적으로 Worker 클래스가 사용됩니다.
ctor
새 Worker의 생성자에 전달할 인수 배열

Examples

예제 #1 Creating Pools

                  
<?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)
}