norberttech / symfony-process-executor
Symfony Process Component on steroids, async/sync execution chain.
Installs: 169 724
Dependents: 1
Suggesters: 0
Security: 0
Stars: 12
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^8.2
- aeon-php/sleep: ^1.0
- symfony/process: ^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0
- 3.x-dev
- 2.x-dev
- 2.2.0
- 2.1.0
- 2.0.x-dev
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.0.x-dev
- 1.0.0
- dev-update-dependencies
- dev-dependabot/composer/tools/phpstan/phpstan-2.1.13
- dev-dependabot/composer/tools/vimeo/psalm-6.2.0
- dev-dependabot/composer/tools/phpstan/phpstan-2.1.2
- dev-dependabot/composer/tools/symfony/process-5.4.46
- dev-dependabot/composer/symfony/process-6.4.14
- dev-renovate/configure
- dev-updated/dependencies
- dev-feature/sleep-update
This package is auto-updated.
Last update: 2025-05-02 18:16:17 UTC
README
Tiny library that simplifies launching multiple processes in parallel (or not).
Installation
composer require norberttech/symfony-process-executor
Examples
<?php use NorbertTech\SymfonyProcessExecutor\AsynchronousExecutor; use NorbertTech\SymfonyProcessExecutor\ProcessPool; use NorbertTech\SymfonyProcessExecutor\ProcessWrapper; use Symfony\Component\Process\Process; use Aeon\Calendar\TimeUnit; $processes = new ProcessPool( Process::fromShellCommandline('sleep 1 && echo 1'), Process::fromShellCommandline('sleep 2 && echo 2'), Process::fromShellCommandline('sleep 3 && echo 3'), Process::fromShellCommandline('sleep 4 && echo 4'), Process::fromShellCommandline('sleep 5 && echo 5') ); $executor = new AsynchronousExecutor( pool: $processes, sleep: TimeUnit::milliseconds(100), // delay between checking for process completion timeout: TimeUnit::seconds(12), // total timeout for all processes batchSize: 2 // number of processes to run in parallel at once, when null all processes will be run in parallel ); $executor->execute(); $executor->pool()->each(function (ProcessWrapper $processWrapper) { var_dump($processWrapper->exitCode()); var_dump(\trim($processWrapper->output())); var_dump($processWrapper->executionTime()->inSeconds()); var_dump($processWrapper->executionTime()->inMilliseconds()); var_dump($processWrapper->executionTime()->microsecond()); echo "----\n"; }); echo \sprintf("Successfully finished child processes: %d\n", $executor->pool()->withSuccessExitCode()); echo \sprintf("Failure finished child processes: %d\n", $executor->pool()->withFailureExitCode()); echo \sprintf("Total execution time [s]: %d\n", $executor->executionTime()->inSecondsPreciseString());
Output:
php examples/async_multiple_success_processes.php int(0) string(1) "1" int(1) int(1033) int(1033295) ---- int(0) string(1) "2" int(2) int(2064) int(2064680) ---- int(0) string(1) "3" int(3) int(3092) int(3092137) ---- int(0) string(1) "4" int(4) int(4026) int(4026060) ---- int(0) string(1) "5" int(5) int(5052) int(5052531) ---- Successfully finished child processes: 5 Failure finished child processes: 0 Total execution time [s]: 5
Tests
All tests for this library are written as phpt files, you can read more about it here https://qa.php.net/phpt_details.php.
In order to launch full testsuite use composer
composer tests