Danny Valariola
Danny Valariola

Reputation: 1118

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?

Upvotes: 3

Views: 7790

Answers (1)

Nadir Latif
Nadir Latif

Reputation: 3763

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

Upvotes: 1

Related Questions