gpt4 book ai didi

php - guzzlephp(或 php-ga-measurement-protocol)中的异步请求

转载 作者:行者123 更新时间:2023-12-03 15:56:19 25 4
gpt4 key购买 nike

有谁知道如何使用 guzzlephp 发送工作且非阻塞的异步请求?

似乎对此有支持,但似乎没有实现

<?php

$this->guzzle->requestAsync('post', 'http://', ['synchronous' => false])->wait();

?>

从某种意义上说,它不等待响应。

php-ga-measurement-protocol也有问题
$analytics->setAsyncRequest(true)->sendPageview(); 

最佳答案

你在说什么问题?

正如您所描述的,异步请求在 Guzzle 中工作正常。你只是得到requestAsync()的 promise 当你准备好时,立即做其他事情并做出回应。

// ['synchronous' => false] is not required.
$responsePromise = $this->guzzle->requestAsync('post', 'http://...');

// Your stuff...

$response = $responsePromise->wait();

不知道 php-ga-measurement-protocol,顺便说一句,但似乎这个库也正确地实现了它们。

关于php - guzzlephp(或 php-ga-measurement-protocol)中的异步请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43755986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com