有谁知道如何使用 guzzlephp 发送工作且非阻塞的异步请求?
似乎对此有支持,但似乎没有实施
<?php
$this->guzzle->requestAsync('post', 'http://', ['synchronous' => false])->wait();
?>
从某种意义上说,它不等待响应。
php-ga-measurement-protocol也有问题
$analytics->setAsyncRequest(true)->sendPageview();
有谁知道如何使用 guzzlephp 发送工作且非阻塞的异步请求?
似乎对此有支持,但似乎没有实施
<?php
$this->guzzle->requestAsync('post', 'http://', ['synchronous' => false])->wait();
?>
从某种意义上说,它不等待响应。
php-ga-measurement-protocol也有问题
$analytics->setAsyncRequest(true)->sendPageview();
你在说什么问题?
正如您所描述的,异步请求在 Guzzle 中工作正常。requestAsync()
当你准备好时,你只需立即得到一个承诺,做其他事情并接受回应。
// ['synchronous' => false] is not required.
$responsePromise = $this->guzzle->requestAsync('post', 'http://...');
// Your stuff...
$response = $responsePromise->wait();
不知道 php-ga-measurement-protocol,顺便说一句,但似乎这个库也正确地实现了它们。