/** * * @param int $count * worker process count * Run the application by entering the event loop * @throws \RuntimeException If a loop was not previously specified */ public function run($count = 1) { if (null === $this->loop) { throw new \RuntimeException("A React Loop was not provided during instantiation"); } if ($count <= 1) { $this->loop->run(); } else { $loop = $this->loop; $master = new \Jenner\SimpleFork\FixedPool(function () use($loop) { $this->loop->run(); }, $count); $master->start(); $master->keep(true); // or just // $master = new \React\Multi\Master($this->loop, $count); // $master->start(); } }
<?php /** * @author Jenner <*****@*****.**> * @blog http://www.huyanping.cn * @license https://opensource.org/licenses/MIT MIT * @datetime: 2015/11/19 21:25 */ require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; class TestRunnable implements \Jenner\SimpleFork\Runnable { /** * @return mixed */ public function run() { sleep(10); echo getmypid() . ':done' . PHP_EOL; } } $pool = new \Jenner\SimpleFork\FixedPool(2); $pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable())); $pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable())); $pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable())); $pool->wait();