PHP code example of graze / parallel-process

1. Go to this page and download the library: Download graze/parallel-process 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/ */

    

graze / parallel-process example snippets


$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

$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

$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();

$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();