发送异步请求,而无需等待使用 guzzle 的响应
2022-08-30 20:08:40
我有以下两个功能
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait')->wait();
$this->logger->debug("I shouldn't wait");
}
public function doNotWait(){
sleep(10);
$this->logger->debug("You shouldn't wait");
}
现在我需要在日志中看到的是:
Started
I shouldn't wait
You shouldn't wait
但我所看到的
Started
You shouldn't wait
I shouldn't wait
我也尝试使用以下方法:
方式 #1
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait', ['synchronous' => false])->wait();
$this->logger->debug("I shouldn't wait");
}
方式 #2
public function myEndpoint(){
$this->logger->debug('Started');
$this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait');
$queue = \GuzzleHttp\Promise\queue()->run();
$this->logger->debug("I shouldn't wait");
}
但结果从来都不是想要的。有什么想法吗?我正在使用Guzzle 6.x。