mirror of
https://github.com/danog/php-tokio.git
synced 2024-11-26 12:24:58 +01:00
28 lines
596 B
PHP
28 lines
596 B
PHP
<?php declare(strict_types=1);
|
|
|
|
use Reqwest\Client;
|
|
|
|
use function Amp\async;
|
|
use function Amp\Future\await;
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
Client::init();
|
|
|
|
function test(int $delay): void
|
|
{
|
|
$url = "https://httpbin.org/delay/$delay";
|
|
$t = time();
|
|
echo "Making async reqwest to $url that will return after $delay seconds...".PHP_EOL;
|
|
Client::get($url);
|
|
$t = time() - $t;
|
|
echo "Got response from $url after ~".$t." seconds!".PHP_EOL;
|
|
};
|
|
|
|
$futures = [];
|
|
$futures []= async(test(...), 5);
|
|
$futures []= async(test(...), 5);
|
|
$futures []= async(test(...), 5);
|
|
|
|
await($futures);
|