Symfony HttpClient
A low-overhead, high-performance PHP HTTP client with sync, async, and streaming support
Repository Health
Technical Analysis
Symfony HttpClient is the HTTP client component from the Symfony framework, providing a unified API for making synchronous and asynchronous HTTP requests from PHP. It wraps native cURL bindings (via CurlHttpClient) with a pure-PHP stream fallback (NativeHttpClient), giving it near-zero overhead while still supporting HTTP/2 multiplexing, concurrent requests, and streaming responses without blocking.
Beyond the base transport, the component ships decorators for retries, caching, throttling, mocking in tests, and PSR-18/HTTPlug interoperability, making it usable both as a standalone client and as a drop-in replacement for Guzzle in libraries that expect a PSR-compliant HTTP client.
What You Get
- A unified
HttpClientInterfacewith both synchronous and asynchronous request semantics - Native cURL transport (CurlHttpClient) supporting HTTP/2 push and multiplexed concurrent requests
- A pure-PHP fallback (NativeHttpClient) for environments without the cURL extension
- Built-in decorators for retry logic, response caching, throttling, and request/response tracing
- PSR-18 and HTTPlug adapters (Psr18Client, HttplugClient) for drop-in compatibility with libraries expecting those interfaces
- A MockHttpClient for deterministic HTTP testing without network calls
Common Use Cases
- Calling third-party REST APIs from a Symfony (or any PHP) application with automatic retries and timeouts
- Streaming large HTTP responses (downloads, server-sent events) without loading the full body into memory
- Firing off many concurrent outbound requests (e.g. webhook fan-out or multi-source aggregation) using async/multiplexed I/O
- Swapping in as a PSR-18 client for libraries (like league/oauth2-client or API SDKs) that only depend on the PSR interface
Under The Hood
Architecture: The component centers on a single HttpClientInterface with two production backends selected at runtime — CurlHttpClient (preferred, using native cURL multi-handles for HTTP/2 multiplexing and concurrency) and NativeHttpClient (a pure-PHP stream-based fallback). Responses are lazy: ResponseInterface implementations only block on getContent()/getStatusCode(), letting many requests run concurrently and be awaited individually. A decorator chain (RetryableHttpClient, CachingHttpClient, ThrottlingHttpClient, TraceableHttpClient, ScopingHttpClient) wraps the base client to compose cross-cutting behavior without touching core transport code.
Tech Stack: Pure PHP 8.4+, zero mandatory runtime dependencies beyond psr/log and Symfony’s own contracts packages; optional integrations include amphp/http-client, Guzzle, and PSR-7 implementations (nyholm/psr7) for interoperability testing. Build/test tooling uses PHPUnit via phpunit.xml.dist.
Code Quality: The Tests/ directory contains 22+ test files covering the curl, native, mock, retry, caching, and PSR-18 decorators individually, with a shared HttpClientTestCase base exercising common contract behavior across backends. Naming is consistent (*HttpClient, *Trait for shared decorator logic), and exceptions are modeled as a dedicated Exception namespace rather than generic \Exception throws.
API Design: The public surface is intentionally small — request(), stream(), and a handful of options arrays — which keeps the learning curve low despite the component’s internal complexity. PSR-18 and HTTPlug adapter classes mean existing PSR-consuming code needs no changes to swap in this client, a strong developer-experience win for library authors.
Used by 10 apps in this directory
Akaunting
Invoicing Finance
Open-source online accounting for small businesses and freelancers — invoices, expenses, and reporting without monthly fees or vendor lock-in.
Coolify
Devops · Hosting Control Panel
Open-source self-hosted PaaS — deploy apps, databases and 280+ services on your own servers with no vendor lock-in
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Hi.Events
Ecommerce · Scheduling
Self-hosted event ticketing platform that keeps your attendee data, brand, and revenue completely under your control.
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
Pixelfed
Social Media
A decentralized, self-hosted photo sharing platform built on ActivityPub for the open Fediverse.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.