#!/usr/bin/php $promise) { if ($promise->isResolved()) { unset($promises[$index]); if (!$promise->isEmpty() && !$promise->isError()) print($promise->getValue() . PHP_EOL); } } } /* * Example of asynchronous processing in PHP */ $process = function ($i) { $delayMicroseconds = (5 - $i) * 1000000; usleep($delayMicroseconds); return sprintf( 'PID %-5d slept for %.1f seconds', getmypid(), $delayMicroseconds / 1000000 ); }; $promises = []; foreach (range(0, 5) as $i) $promises[] = async($process, $i); while (count($promises) > 0) awaitPromises($promises);