graze / 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 17:59:39 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)。请参阅 许可证文件 了解更多信息。