我正在尝试在 PHP 中使用 Guzzle 池。但是我在处理 ASYNC 请求时遇到了困难。下面是代码片段。
$client = new \GuzzleHttp\Client();
function test()
{
$client = new \GuzzleHttp\Client();
$request = $client->createRequest('GET', 'http://l/?n=0', ['future' => true]);
$client->send($request)->then(function ($response) {
//echo 'Got a response! ' . $response;
return "\n".$response->getBody();
});
}
$res = test();
var_dump($res); // echoes null - I know why it does so but how to resolve the issue.
有谁可以让函数等待并获得正确的结果。