2017 © Pedro Peláez
 

library parallel-process

run a pool of processes simultaneously

image

graze/parallel-process

run a pool of processes simultaneously

  • Tuesday, May 22, 2018
  • by graze
  • Repository
  • 11 Watchers
  • 14 Stars
  • 5,926 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 3 Open issues
  • 15 Versions
  • 34 % Grown

The README.md

Parallel Process

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

Run multiple Symfony\Process's at the same time., (*2)

giphy, (*3)

Install

Via Composer, (*4)

$ composer require graze/parallel-process

If you want to use Tables or Lines to output to the console, include:, (*5)

$ composer require graze/console-diff-renderer

Usage

``` php $pool = new Pool(); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new Process('sleep 100')); $pool->add(new ProcessRun(new Process('sleep 100'))); $pool->run(); // blocking that will run till it finishes, (*6)


A Pool will run all child processes at the same time. ### Priority Pool A Priority pool will sort the runs to allow a prioritised list to be started. You can also limit the number of processes to run at a time. ```php $pool = new PriorityPool(); $pool->add(new Process('sleep 100'), [], 1); $pool->add(new Process('sleep 100'), [], 0.1); $pool->add(new Process('sleep 100'), [], 5); $pool->add(new Process('sleep 100'), [], 10); $pool->add(new CallbackRun( function () { return 'yarp'; }, [], 2 ); $pool->run(); // blocking that will run till it finishes

Recursive Pools

You can add a Pool as a child to a parent pool. A Pool will act just like a standard run and hide the child runs., (*7)

If the parent is a PriorityPool, it will control all the child runs so that priorities and the max simultaneous configuration options still apply., (*8)

$pool = new Pool();
$pool->add(new Process('sleep 100'));
$pool2 = new Pool();
$pool2->add(new Process('sleep 100'));
$pool->add($pool2);
$pool->run(); // blocking that will run till it finishes

Display

You can output runs in a few different ways to the command line. These require the use of the package: graze/console-diff-renderer., (*9)

Table

Visual output of the parallel processes, (*10)

$pool = new \Graze\ParallelProcess\PriorityPool();
for ($i = 0; $i < 5; $i++) {
    $time = $i + 5;
    $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' => $time]);
}
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$table = new \Graze\ParallelProcess\Display\Table($output, $pool);
$table->run();

asciicast, (*11)

Lines

Write the output of each process to the screen, (*12)

$pool = new \Graze\ParallelProcess\PriorityPool();
$pool->setMaxSimultaneous(3);
for ($i = 0; $i < 5; $i++) {
    $time = $i + 5;
    $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]);
}
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$lines = new \Graze\ParallelProcess\Display\Lines($output, $pool);
$lines->run();

asciicast, (*13)

Testing

bash $ make test, (*14)

Contributing

Please see CONTRIBUTING for details., (*15)

Security

If you discover any security related issues, please email security@graze.com instead of using the issue tracker., (*16)

Credits

License

The MIT License (MIT). Please see License File for more information., (*17)

The Versions