A simple to use process executor.
- php: ~7.0
- psr/log: ~1.0
- symfony/process: ~4.0|~3.0|~2.8
Through Composer as saxulum/saxulum-processes-executor.
<?php
use Symfony\Component\Process\Process;
use Saxulum\ProcessesExecutor\ProcessesExecutor;
$processes = [
new Process('php subprocess1.php'),
new Process('php subprocess2.php'),
new Process('php subprocess3.php'),
new Process('php subprocess4.php'),
new Process('php subprocess5.php'),
];
$startedCommandLines = [];
$executor = new ProcessesExecutor();
$executor->execute($processes);
<?php
use Symfony\Component\Process\Process;
use Saxulum\ProcessesExecutor\ProcessesExecutor;
$processes = [
new Process('php subprocess1.php'),
new Process('php subprocess2.php'),
new Process('php subprocess3.php'),
new Process('php subprocess4.php'),
new Process('php subprocess5.php'),
];
$startedCommandLines = [];
$executor = new ProcessesExecutor();
$executor->execute(
$processes,
function (Process $process, $key) use (&$startedProcesses) {
$startedCommandLines[$key] = $process->getCommandLine();
}
);
<?php
use Symfony\Component\Process\Process;
use Saxulum\ProcessesExecutor\ProcessesExecutor;
$processes = [
new Process('php subprocess1.php'),
new Process('php subprocess2.php'),
new Process('php subprocess3.php'),
new Process('php subprocess4.php'),
new Process('php subprocess5.php'),
];
$outputs = [];
$errorOutputs = [];
$executor = new ProcessesExecutor();
$executor->execute(
$processes,
null,
function (array $processes) use (&$outputs, &$errorOutputs) {
foreach ($processes as $key => $process) {
/** @var Process $process */
if ('' !== $output = $process->getIncrementalOutput()) {
if (!isset($outputs[$key])) {
$outputs[$key] = '';
}
$outputs[$key] .= $output;
}
if ('' !== $errorOutput = $process->getIncrementalErrorOutput()) {
if (!isset($outputs[$key])) {
$errorOutputs[$key] = '';
}
$errorOutputs[$key] .= $errorOutput;
}
}
}
);
<?php
use Symfony\Component\Process\Process;
use Saxulum\ProcessesExecutor\ProcessesExecutor;
$processes = [
new Process('php subprocess1.php'),
new Process('php subprocess2.php'),
new Process('php subprocess3.php'),
new Process('php subprocess4.php'),
new Process('php subprocess5.php'),
];
$outputs = [];
$errorOutputs = [];
$executor = new ProcessesExecutor();
$executor->execute(
$processes,
null,
null,
function (Process $process, $key) use (&$outputs, &$errorOutputs) {
if ('' !== $output = $process->getOutput()) {
$outputs[$key] = $output;
}
if ('' !== $errorOutput = $process->getErrorOutput()) {
$errorOutputs[$key] = $errorOutput;
}
}
);
Dominik Zogg 2016