verbb / parallel-process
同时运行进程池
1.0.3
2024-05-26 12:20 UTC
Requires
- php: ^5.5 | ^7.0 | ^8.0
- graze/data-structure: ^2.0
- psr/log: ^1.0 | ^2.0 | ^3.0
- symfony/event-dispatcher: ^2.8 | ^3.2 | ^4.0 | ^5.0 | ^6.0 | ^7.0
- symfony/process: ^2.8 | ^3.2 | ^4.0 | ^5.0 | ^6.0 | ^7.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.3.1
- symfony/console: ^3.1 | ^4 | ^5
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-08-26 12:58:46 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)。有关更多信息,请参阅许可证文件。