This content originally appeared on DEV Community and was authored by Bilal Haidar
Did you know you can send multiple HTTP requests in parallel in Laravel, instead of one after another?
That’s what Http::pool() does. It’s built on top of Guzzle and can massively boost performance when fetching data from several APIs at once.
🧠 The idea
Normally, you might do this:
$response1 = Http::get('https://api.example.com/users');
$response2 = Http::get('https://api.example.com/posts');
$response3 = Http::get('https://api.example.com/comments');
Each waits for the previous one.
If each takes 1 second → total ≈ 3 seconds.
With Http::pool(), Laravel runs them all at once — so the total time ≈ the longest single request (around 1 second here).
🧩 Example
use Illuminate\Support\Facades\Http;
$responses = Http::pool(fn ($pool) => [
$pool->as('users')->get('https://api.example.com/users'),
$pool->as('posts')->get('https://api.example.com/posts'),
$pool->as('comments')->get('https://api.example.com/comments'),
]);
$users = $responses['users'];
$posts = $responses['posts'];
$comments = $responses['comments'];
$usersData = $users->json();
⚙️ How it works
- The
pool()method accepts a closure. - Inside, you define multiple requests.
- Laravel runs them concurrently using Guzzle promises.
- Returns an array of responses (each is a standard Response instance).
🧩 Dynamic example
$urls = [
'https://api.example.com/products/1',
'https://api.example.com/products/2',
'https://api.example.com/products/3',
];
$responses = Http::pool(fn ($pool) =>
collect($urls)->map(fn($url) => $pool->get($url))->all()
);
foreach ($responses as $response) {
dump($response->json());
}
🛠 When to use it
✅ Fetch data from multiple APIs simultaneously
✅ Speed up microservice calls
✅ Reduce latency in dashboards or data aggregators
💬 Have you used Http::pool()before?
Share your favorite use case or performance boost story 👇
Laravel #WebDevelopment #FullStackDev #Performance #PHP #LaravelTips
This content originally appeared on DEV Community and was authored by Bilal Haidar
Bilal Haidar | Sciencx (2025-10-21T06:24:54+00:00) 💥 Supercharge your Laravel API calls with Http::pool(). Retrieved from https://www.scien.cx/2025/10/21/%f0%9f%92%a5-supercharge-your-laravel-api-calls-with-httppool/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.