Skip to content

CurlTransport

Zero-dependency PSR-18 transport built on ext-curl and the Nyholm PSR-17 factory (already a hard framework dependency).

This is the default transport so the HTTP client abstraction works out of the box with no extra Composer package; TransportFactory prefers Guzzle when it is installed.

Failure mapping follows PSR-18: a connectivity failure (DNS, refused, reset, timeout) throws NetworkException; an unusable request throws RequestException; a real HTTP response — including 4xx/5xx — is returned, never thrown (status handling is the caller’s job).

final class CurlTransport implements ClientInterface

ImplementsClientInterface
SourceHttp/Client/CurlTransport.php

public function __construct(ResponseFactoryInterface $responseFactory = new Psr17Factory(…), StreamFactoryInterface $streamFactory = new Psr17Factory(…), float $timeoutSeconds = 30.0, float $connectTimeoutSeconds = 10.0): mixed

ParameterTypeDescription
$responseFactoryResponseFactoryInterface
$streamFactoryStreamFactoryInterface
$timeoutSecondsfloat
$connectTimeoutSecondsfloat

Returns mixed

MethodDescription
sendRequest(RequestInterface $request): ResponseInterfacePerforms the request with curl and builds a PSR-7 response from the result.

public function sendRequest(RequestInterface $request): ResponseInterface

Performs the request with curl and builds a PSR-7 response from the result.

Redirects are not followed, so a 3xx is returned as-is; response headers are collected line by line and re-added to the response, preserving repeated names. Any HTTP status, including 4xx and 5xx, is returned rather than thrown.

ParameterTypeDescription
$requestRequestInterface

Returns ResponseInterface

ThrowsWhen
NetworkExceptionwhen curl reports a connectivity-level failure (DNS, connect, timeout, TLS handshake, or a truncated exchange)
RequestExceptionwhen the URI or the HTTP method is empty, or curl fails for any other reason