I have the following code:
$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();
I'm not sure I'm using the "wait" properly, but I want the process to be async. Currently, the request hangs and if I omit the wait then the pool will not be sent at all. Ideas?
Guzzle 文档描述了如何使用 promise 发出多个并发请求: http ://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.