intermezzon / asyncprocess
Execute multiple processes asynchronously
Installs: 2 446
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2025-04-06 19:12:52 UTC
README
Helper to start multiple processes simultaneously.
Lets start with an example:
$pool = new \Intermezzon\AsyncProcess\Pool(); $pool->addCommand('php -r "echo \"Start process.\"; sleep(2); echo \"Process ended\";"'); // Wait for all commands to be done $pool->executeAndWait();
You may start multiple processes simultaneously
$pool = new \Intermezzon\AsyncProcess\Pool(); $pool->addCommand('php -r "echo \"Start process 1.\n\"; sleep(2); echo \"Process 1 ended\n\";"'); $pool->addCommand('php -r "echo \"Start process 2.\n\"; sleep(1); echo \"Process 2 ended\n\";"'); // Wait for all commands to be done $pool->executeAndWait();
Events
You may also monitor output, errors and handle ended process
$pool = new \Intermezzon\AsyncProcess\Pool(); $pool->addCommand('my_program') ->started(function ($command)) { echo "Process has started\n"; }) ->output(function ($command, $output) { echo "Process outputed:" . $output . "\n"; // Send stuff to process stdin $command->input("send this input to process stdin"); }) ->error(function ($command, $error) { echo "Process send error: " . $error ."\n"; }) ->ended(function ($command, $exitCode) { echo "Process ended with exit code: " . $exitCode . "\n"; echo "Process took " . $command->totalTime . " seconds to execute."; }); // Wait for all commands to be done $pool->executeAndWait();
Settings
You may want to limit the number of simultaneously running processes so that you do not overload your system.
$pool = new \Intermezzon\AsyncProcess\Pool(); $pool->setMaxProcesses(3);
Kudoz
This has been inspired by