andytruong/php-pool

This package's canonical repository appears to be gone and the package has been frozen as a result.

dev-master 2019-01-09 00:36 UTC

This package is auto-updated.

Last update: 2023-02-09 10:47:22 UTC


README

Run tasks in parallel with limited threads.

Example usage:

<?php
$pool = new andytruong\pool\Pool($poolSize = 3);

$tasks = [1, 2, 3, 4, 5];
foreach ($tasks as $task) {
    $pool->execute(
        function($task) {
            echo "[callback] processing {$task}" . PHP_EOL;
            sleep(5); # slow task process
            echo "[callback] completed {$task}" . PHP_EOL;
        },
        [$task]
    );
}

$pool->wait();

Install

composer require andytruong/php-pool