* in order to have more (or the same) control over the queue and when it ends - while SwarmProcess is running
 * the jobs you gave it to run.
 *
 * This examples shows the simplest way of using the SwarmProcess class.
 * The logger is used purely to allow you to see what's happening.
 * If you don't provide the logger, the Psr\Log\NullLogger will be used internally.
 */
use Afrihost\SwarmProcess\SwarmProcess;
use Monolog\Logger;
use Symfony\Component\Process\Process;
chdir(__DIR__);
require '../vendor/autoload.php';
$logger = new Logger('swarm_logger');
$swarmProcess = new SwarmProcess($logger);
// Add a few things to do:
$swarmProcess->pushProcessOnQueue(new Process('sleep 9'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 8'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 7'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 6'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 5'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 5'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 4'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 3'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 2'));
$swarmProcess->pushProcessOnQueue(new Process('sleep 1'));
$swarmProcess->setMaxRunStackSize(4);
/**
 * @return null|Process
 */
$closureAddMoreStuff = function () {
    if (rand(0, 1000) == 0) {
Пример #2
0
 * If you don't provide the logger, the Psr\Log\NullLogger will be used internally.
 */
use Afrihost\SwarmProcess\SwarmProcess;
use Monolog\Logger;
use Symfony\Component\Process\Process;
chdir(__DIR__);
require '../vendor/autoload.php';
$logger = new Logger('swarm_logger');
$swarmProcess = new SwarmProcess($logger);
// Build a list of things we'll be adding later on
$add_these = array();
$add_these[] = new Process('sleep 9');
$add_these[] = new Process('sleep 8');
$add_these[] = new Process('sleep 7');
$add_these[] = new Process('sleep 6');
$add_these[] = new Process('sleep 5');
$add_these[] = new Process('sleep 5');
$add_these[] = new Process('sleep 4');
$add_these[] = new Process('sleep 3');
$add_these[] = new Process('sleep 2');
$add_these[] = new Process('sleep 1');
$swarmProcess->setMaxRunStackSize(4);
do {
    try {
        if (count($add_these) > 0) {
            $swarmProcess->pushProcessOnQueue(array_shift($add_these));
        }
    } catch (Exception $e) {
        // do something intelligent with the exception - but do not let the loop end, you will lose work
    }
} while ($swarmProcess->tick());