adrian-dussan / parallel-process
同时运行进程池
0.8.1
2018-09-25 09:06 UTC
Requires
- php: ^5.5 | ^7.0
- graze/data-structure: ^2.0
- psr/log: ^1.0
- symfony/event-dispatcher: ^2.8 | ^3.2 | ^4.0
- symfony/process: ^2.8 | ^3.2 | ^4.0
Requires (Dev)
- graze/console-diff-renderer: ^0.6.1
- graze/standards: ^2
- mockery/mockery: ^1.0
- phpunit/phpunit: ^5.7.21|^6|^7
- squizlabs/php_codesniffer: ^3
- symfony/console: ^3.1 | ^4
Suggests
- graze/console-diff-renderer: required to use Table and Lines
- symfony/console: To use the Table to print current runs
This package is auto-updated.
Last update: 2024-09-17 22:44:50 UTC
README
同时运行多个Symfony\Process
安装
通过Composer
$ composer require graze/parallel-process
如果您想使用表格或行输出到控制台,请包含
$ composer require graze/console-diff-renderer
使用方法
$pool = new Pool(); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new ProcessRun(new Process('sleep 100'))); $pool->run(); // blocking that will run till it finishes
进程池将同时运行所有子进程。
优先级进程池
优先级进程池将对运行进行排序,以便启动优先级列表。您还可以限制同时运行的进程数量。
$pool = new PriorityPool(); $pool->add(new Process('sleep 100'), [], 1); $pool->add(new Process('sleep 100'), [], 0.1); $pool->add(new Process('sleep 100'), [], 5); $pool->add(new Process('sleep 100'), [], 10); $pool->add(new CallbackRun( function () { return 'yarp'; }, [], 2 ); $pool->run(); // blocking that will run till it finishes
递归进程池
您可以将进程池作为子进程添加到父进程池中。进程池将像标准运行一样操作,并隐藏子进程。
如果父进程是PriorityPool,它将控制所有子进程,以便优先级和最大同时配置选项仍然适用。
$pool = new Pool(); $pool->add(new Process('sleep 100')); $pool2 = new Pool(); $pool2->add(new Process('sleep 100')); $pool->add($pool2); $pool->run(); // blocking that will run till it finishes
显示
您可以将运行输出到命令行的方式有几种。这些需要使用包:graze/console-diff-renderer
。
表格
并行进程的视觉输出
$pool = new \Graze\ParallelProcess\PriorityPool(); for ($i = 0; $i < 5; $i++) { $time = $i + 5; $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' => $time]); } $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $table = new \Graze\ParallelProcess\Display\Table($output, $pool); $table->run();
行
将每个进程的输出写入屏幕
$pool = new \Graze\ParallelProcess\PriorityPool(); $pool->setMaxSimultaneous(3); for ($i = 0; $i < 5; $i++) { $time = $i + 5; $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]); } $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $lines = new \Graze\ParallelProcess\Display\Lines($output, $pool); $lines->run();
测试
$ make test
贡献
请参阅CONTRIBUTING以获取详细信息。
安全
如果您发现任何安全问题,请通过电子邮件security@graze.com报告,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。