gpt4 book ai didi

php - Guzzle HTTP 异步池请求

转载 作者:可可西里 更新时间:2023-11-01 16:36:28 26 4
gpt4 key购买 nike

我有以下代码:

$client = new Client($conf);

//Pool of requests
$requests = function ($data) use ($client) {
yield function () use ($client, $pixel) {
....
}
}
//Pool of fullfilled
$fullfilled = function ($response, $index) use ($data) {
...
}
//Pool of rejected
$rejected = function ($reason, $index) use ($data) {
...
}

$pool = new Pool($client, $requests($data), [
'concurrency' => 10, 'fulfilled' => $fullfilled, 'rejected' => $rejected
]);

// Initiate the transfers and create a promise
$promise = $pool->promise();
$promise->wait();

我不确定我是否正确使用了“等待”,但我希望进程是异步的。目前,请求挂起,如果我省略等待,则根本不会发送池。想法?

最佳答案

Guzzle 文档描述了如何使用 promise 发出多个并发请求:http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests

关于php - Guzzle HTTP 异步池请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42340198/

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