<?php
/**
* @return Generator
*/
function test() {
echo "Preparing generator.", PHP_EOL;
$start = microtime(true);
$first = (yield Async::call("file_get_contents", array("http://www.php.net")));
echo "Receiving first result: ", number_format((microtime(true) - $start) * 1e3, 2), 'ms', PHP_EOL;
$second = (yield Async::call("file_get_contents", array("http://www.alpari.ru")));
echo "Receiving second result: ", number_format((microtime(true) - $start) * 1e3, 2), 'ms', PHP_EOL;
echo "Asynchronous result received: ", strlen((string) $first), ' and ', strlen((string) $second), 'bytes', PHP_EOL;
echo "Total: ", number_format((microtime(true) - $start) * 1e3, 2), 'ms', PHP_EOL;
};
echo "<pre>";
$future = test();
preferences:
38.81 ms | 402 KiB | 5 Q