Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\parallel(int $n, callable $fn)
Set the number to concurrent coroutines
The function to be executed
if success, it returns TRUE, otherwise it returns FALSE.
Execute the function within multiple coroutines in concurrently.
since v4.5.3
<?php
declare(strict_types=1);
use OpenSwoole\Coroutine;
use OpenSwoole\Runtime;
use function OpenSwoole\Coroutine\parallel;
co::run(function() {
$c = 4;
$results = [];
parallel($c, function () use (&$results) {
System::usleep(200000);
$results[] = System::gethostbyname('localhost');
});
var_dump($results);
});