How to perform multiple Guzzle requests at the same time?

How to perform multiple Guzzle requests at the same time?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to Perform Multiple Guzzle Requests at the Same Time

If you are relying on Guzzle's default send() method for every request, you are likely treating your HTTP client like a sequential worker rather than a concurrent engine. The underlying library supports parallelism through cURL's multi-handle capabilities, but exposing that directly often leads to fragile code. Fortunately, the modern approach shifts away from managing low-level cURL handles and instead leverages Guzzle's built-in asynchronous mechanisms or dedicated batching utilities depending on your specific PHP version and constraints.

To execute multiple requests simultaneously in a synchronous flow without blocking the event loop unnecessarily, you should utilize Guzzle's Pool component. This is distinct from simply creating a large array of clients; the Pool manages a collection of ClientInterface instances and batches them to send concurrently. This approach abstracts the complexity of cURL multi-handles while retaining the performance benefits of true parallelism.

Here is how you structure a synchronous batch operation using the Pool:

use GuzzleHttp\Pool;
use GuzzleHttp\Psr7\Response;

$pool = new Pool($client, $requests, [
    'concurrency' => 5, // Number of simultaneous requests
    'fulfilled'       => function (Response $response, RequestInterface $request) {
        // Handle successful response
        // $response is the result for $request
    },
    'rejected'        => function ($reason, RequestInterface $request) {
        // Handle error
        // $reason can be an exception or a thrown error
    }
]);

// Wait for all requests to complete and get results
$results = $pool->promise()->wait();

The concurrency parameter is critical here. It dictates how many HTTP connections are active at any given moment. Setting this too low defeats the purpose of parallelism, while setting it higher than your server can handle—either on your application side or the remote API side—can lead to rate limiting issues or connection exhaustion. Always verify the rate limits of the external APIs you are hitting before aggressively increasing this number.

For scenarios involving PHP 7.4 and later, Guzzle introduces a more robust batching system that simplifies the syntax significantly. You can use GuzzleHttp\Middleware::batch(). This middleware intercepts requests, groups them into batches, and then sends them in parallel. It is particularly useful when you have a dynamic list of requests generated at runtime, as it avoids the need to manually instantiate multiple client instances or manage complex promise chains yourself.

use GuzzleHttp\Middleware;

$batchMiddleware = Middleware::batch(5); // Batch size acts as concurrency limit

$requestFactory = function ($uri) use ($httpClient) {
    return $httpClient->createRequest('GET', $uri);
};

// Apply the middleware to your client or handler chain
$handlerStack = HandlerStack::create($defaultHandler);
$handlerStack->push($batchMiddleware);

$client = new Client([], ['handler' => $handlerStack]);

When choosing between these approaches, consider that Pool gives you granular control over retry logic and individual request handling within the callback closures. In contrast, the middleware approach is often cleaner for "fire-and-forget" scenarios or when integrating into a larger pipeline where you just need to ensure a bulk of requests don't queue up sequentially.

A common pitfall developers face is confusing asynchronous execution with parallelism. Using AsyncClient allows you to run requests in an event loop, but if you are running a standard synchronous PHP CLI script or a traditional web request handler without Swoole or ReactPHP, the Pool remains the most practical choice for achieving "simultaneous" execution within a blocking context.

Finally, remember that parallelism is not always the silver bullet. If your bottleneck lies in network latency to a distant server, concurrent requests will yield diminishing returns once you hit the connection limit of that remote host. In such cases, tuning concurrency to match the available sockets and the target API's capacity is more effective than simply throwing more requests into the pool.

Our network