| 1 | <?php |
||
| 17 | class FixedPool extends AbstractPool |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var int max process count |
||
| 21 | */ |
||
| 22 | protected $max; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param int $max |
||
| 26 | */ |
||
| 27 | 3 | public function __construct($max = 4) |
|
| 31 | |||
| 32 | 3 | public function execute(Process $process) |
|
| 33 | { |
||
| 34 | 3 | Utils::checkOverwriteRunMethod(get_class($process)); |
|
| 35 | |||
| 36 | 3 | if ($this->aliveCount() < $this->max && !$process->isStarted()) { |
|
| 37 | 3 | $process->start(); |
|
| 38 | 3 | } |
|
| 39 | 3 | array_push($this->processes, $process); |
|
| 40 | 3 | } |
|
| 41 | |||
| 42 | /** |
||
| 43 | * wait for all process done |
||
| 44 | * |
||
| 45 | * @param bool $block block the master process |
||
| 46 | * to keep the sub process count all the time |
||
| 47 | * @param int $interval check time interval |
||
| 48 | */ |
||
| 49 | 3 | public function wait($block = false, $interval = 100) |
|
| 66 | |||
| 67 | } |