Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle HTTP async pool request

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?

like image 867
Danny Valariola Avatar asked Feb 06 '26 05:02

Danny Valariola


1 Answers

The Guzzle documentation describes how to make multiple concurrent requests using promises: http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests

like image 75
Nadir Latif Avatar answered Feb 07 '26 19:02

Nadir Latif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!