graze / parallel-process
run a pool of processes simultaneously
Requires
- php: ^7.4 || ^8.0
- graze/data-structure: ^2.0
- psr/log: ^1.0
- symfony/event-dispatcher: ^5
- symfony/process: ^5
Requires (Dev)
- dms/phpunit-arraysubset-asserts: ^0.5
- graze/console-diff-renderer: ^1.0
- graze/standards: ^2
- mockery/mockery: ^1.6
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.3.1
- symfony/console: ^5
Suggests
- graze/console-diff-renderer: required to use Table and Lines
- symfony/console: To use the Table to print current runs
- dev-master
- v1.0.1
- v1.0.0
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7
- 0.6
- 0.5.1
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1.2
- 0.1.1
- 0.1.0
- dev-fix/makefile-php-versions
- dev-feat/php-8-support
- dev-ci/github-actions
- dev-chore/mockery-phpunit8-floor
- dev-feat/symfony-5-support
- dev-dependabot/composer/phpunit/phpunit-8.5.52
- dev-prioritised
- dev-run-collection
- dev-update-asciicinema
This package is auto-updated.
Last update: 2026-05-28 18:03:07 UTC
README
Run multiple Symfony\Process's at the same time.
Install
Via Composer
$ composer require graze/parallel-process
If you want to use Tables or Lines to output to the console, include:
$ composer require graze/console-diff-renderer
Usage
$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
A Pool will run all child processes at the same time.
Priority Pool
A Priority pool will sort the runs to allow a prioritised list to be started. You can also limit the number of processes to run at a time.
$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
Recursive Pools
You can add a Pool as a child to a parent pool. A Pool will act just like a standard run and hide the child runs.
If the parent is a PriorityPool, it will control all the child runs so that priorities and the max simultaneous configuration options still apply.
$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
Display
You can output runs in a few different ways to the command line. These require the use of the package:
graze/console-diff-renderer.
Table
Visual output of the parallel processes
$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();
Lines
Write the output of each process to the screen
$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();
Testing
$ make test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email security@graze.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.