public function testAliveCount()
 {
     $pool = new \Jenner\SimpleFork\Pool();
     for ($i = 0; $i < 10; $i++) {
         $process = new \Jenner\SimpleFork\Process(function () {
             sleep(3);
         });
         $pool->submit($process);
     }
     $pool->start();
     $this->assertEquals(10, $pool->aliveCount());
     $pool->wait();
 }
Exemple #2
0
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/12
 * Time: 20:38
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
class TestRunnable extends \Jenner\SimpleFork\Runnable
{
    /**
     * 进程执行入口
     * @return mixed
     */
    public function run()
    {
        sleep(10);
        echo getmypid() . ':done' . PHP_EOL;
    }
}
$pool = new \Jenner\SimpleFork\Pool();
$pool->submit(new \Jenner\SimpleFork\Process(new TestRunnable()));
$pool->submit(new \Jenner\SimpleFork\Process(new TestRunnable()));
$pool->submit(new \Jenner\SimpleFork\Process(new TestRunnable()));
$pool->start();
while ($pool->aliveCount() > 0) {
    echo "i am waiting" . PHP_EOL;
    $pool->wait(false);
    sleep(1);
}