php-tokio/examples/reqwest/test.php

26 lines
570 B
PHP
Raw Normal View History

2023-08-27 19:32:52 +02:00
<?php
2023-08-27 20:25:28 +02:00
use Reqwest\Client;
2023-08-27 19:32:52 +02:00
2023-08-27 20:25:28 +02:00
use function Amp\async;
use function Amp\Future\await;
require 'vendor/autoload.php';
Client::init();
2023-08-27 20:40:41 +02:00
function test(int $delay): void {
$url = "https://httpbin.org/delay/$delay";
2023-08-27 20:25:28 +02:00
$t = time();
2023-08-27 20:40:41 +02:00
echo "Making async reqwest to $url that will return after $delay seconds...".PHP_EOL;
Client::get($url);
2023-08-27 20:25:28 +02:00
$t = time() - $t;
echo "Got response from $url after ~".$t." seconds!".PHP_EOL;
};
$futures = [];
2023-08-27 20:40:41 +02:00
$futures []= async(test(...), 5);
$futures []= async(test(...), 5);
$futures []= async(test(...), 5);
2023-08-27 20:25:28 +02:00
await($futures);