puff / http-client
Fiber-aware PSR-18 HTTP client for PHP Unison Fiber Framework
Requires
- php: ^8.2
- psr/http-client: ^1.0
- psr/http-message: ^2.0
- puff/async: dev-main
- puff/client: dev-main
- puff/config: dev-main
- puff/di: dev-main
- puff/http: dev-main
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-08-21 13:31:54 UTC
README
puff/http-client is a Fiber-aware PSR-18 HTTP/1.1 client implemented with native non-blocking PHP streams. It does not require cURL. TCP and TLS transport are provided by puff/client.
composer require puff/http-client
Configuration
The package publishes config/http.client.php. Puff derives the configuration path from the filename, so its values are available under http.client:
return [ 'connect_timeout' => 10.0, 'timeout' => 30.0, 'max_redirects' => 5, 'retries' => 0, 'max_header_size' => 65536, 'max_body_size' => 10485760, ];
A future puff/mqtt-client package should publish config/mqtt.client.php; that file maps independently to mqtt.client. Each protocol package owns its own configuration.
Synchronous PSR-18 usage
use Puff\Http\Factory\RequestFactory; use Puff\HttpClient\HttpClient; $request = (new RequestFactory())->createRequest('GET', 'https://example.com/'); $response = (new HttpClient())->sendRequest($request); echo $response->getStatusCode(); echo (string) $response->getBody();
Asynchronous usage
$pending = $client->sendAsync($request); // Do other event-loop work, or cancel when the result is no longer needed. // $pending->cancel(); $response = $pending->await();
The client supports validated TLS, partial stream reads/writes, Content-Length, chunked responses, EOF-delimited bodies, redirects, cancellation, idempotent retries, response limits, and idle HTTP/1.1 connection reuse. HTTP pipelining is intentionally not used.