public function info()
{
$client = new Client();
$requests = function ($total) {
$baseUri = 'https://www.zlsuper.top';
for ($i = 0; $i < $total; $i++) {
yield new Request('GET', $baseUri);
}
};
$ret = [];
$pool = new Pool($client, $requests(10), [
'concurrency' => 5,
'fulfilled' => function (Response $response, $index) use (&$ret) {
// this is delivered each successful response
$contents = $response->getBody()->getContents();
$contents = json_decode($contents, true);
$ret[$index] = $contents;
},
'rejected' => function (RequestException $reason, $index) {
// this is delivered each failed request
},
]);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();
echo json_encode($ret);
die;
}
网友评论