PHP code example of wulsic / parallel-pool

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

    

wulsic / parallel-pool example snippets




ers = 10;
$jobs = 1000;

$pool = new \Wulsic\Pool\Pool($workers);

echo "Worker count: $workers" . PHP_EOL;

$start = microtime(true);

for($i = 0; $i < $jobs; $i++) {
    echo "Job $i" . PHP_EOL;
    $pool->submit(
        function ($taskId) {
            print "Active task: $taskId" . PHP_EOL;
            return "Finished task: $taskId";
        },
        [$i]
    );
}

while($pool->collect()) {
    continue;
}

$pool->shutdown();

printf(
    "Finished %s threads in %.2f seconds\n",
    $workers ? "with {$workers}" : "without",
    microtime(true) - $start
);