PHP code example of norberttech / symfony-process-executor
1. Go to this page and download the library: Download norberttech/symfony-process-executor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
norberttech / symfony-process-executor example snippets
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());
composer tests
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.