webmaniacs.net / lib-fork
Lib fork 在 PHP 中处理库分叉并支持多线程。灵感来自 duncan3dc/fork-helper
dev-master / 1.0.x-dev
2015-03-19 23:38 UTC
Requires
- php: >=5.5.0
- ext-pcntl: *
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-28 16:51:53 UTC
README
使用以下命令安装最新版本:composer require webmaniacs.net/lib-fork
示例
$manager = new \wmlib\fork\Manager(function(array $error) { print_r($error); die('Child process error'); }); $manager->setNotifier($notifier = new \wmlib\fork\Notifier\Shm()); $manager->child(function (\wmlib\fork\INotifier $notifier, $var) { echo 'Start '.getmypid()."\n"; echo 'Echo from child process with '.$var.' value!'; sleep(1); echo 'End '.getmypid()."\n"; }, ['var' => 'value']); while($manager->loop(10)) { // run 10 forked childs in infinite loop // Manager will handle childs count usleep(10000); } echo "End\n";