spatie / async

Easily run code asynchronously

Home Page:https://spatie.be/en/opensource/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout by pool or by process in pool

vectorkovacspeter opened this issue · comments

Hello,

In the examples I read a comment next to the $pool->timeout function call: // The maximum amount of time a process may take to finish in seconds

So when I set a pool timeout to value 5 and add 20 process to the bool I except that the pool total timaout will be 5*20 = 100 sec, and when a process in the pool takes longer than 5 sec, that one must be call its timeout callback.
But In my sample code I found that the timeout value evaluate by pool, and not by process.
It's a bug or my fault, or som system settings?

sample:

$pool = Pool::create()
    ->concurrency(10)   // The maximum amount of processes which can run simultaneously.
    // The maximum amount of time a process may take to finish in seconds
    // (decimal places are supported for more granular timeouts).
    ->timeout(5)
    ->sleepTime(100);     // Configure how long the loop should sleep before re-checking the process statuses in microseconds.

$rg = range(5,20);

foreach ($rg as $i) {
    $pool
        ->add(async( function () use ($i,$start) {
            $ss = microtime(true);
            $wt=random_int(100, 5000);
            usleep($wt);
            $ee = microtime(true);
            $dd=($ee-$ss);
            return $dd.' usleep('.$wt.') - fromstart: '.($ee-$start);
        }))
        ->then(function ($output) use($i,&$out) {
            $out .= '<br/>'.$i.' -> '.$output;
        })
        ->catch(function (Exception $exception) use($i,&$out) {
            $out .= '<br/>'.$i.' -> <pre>'.$exception->getMessage().'</pre>';
        })
        ->timeout(function () use($i,&$out) {
            $out .= '<br/>'.$i.' -> timeout';
        })
    ;
}

await($pool);

echo $out;

ini_dump.txt
my current phpinfo in the dev conatainer

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.