Connection Pooling

Every backend SDK ships with HTTP connection pooling configured by default. The SDK emits one INFO-level log on client construction listing the effective values so you can verify your configuration.

Defaults

SettingDefaultWhat it does
Max connections per host5Upper bound on concurrent TCP connections to a single host.
Idle timeout55 sCloses a connection that has been idle for this duration.
Connect timeout10 sCaps the TCP + TLS handshake.
Request timeout30 sDefault per-call deadline from request send to full response. Override per call.
Keep-alivealways onHTTP persistent connection reuse. Not user-tunable.

Tune the knobs

Pass the four knobs at client construction.

$client = ClientBuilder::create()
    ->apiKey($apiKey)
    ->apiSecret($apiSecret)
    ->maxConnsPerHost(20)
    ->idleTimeout(55)
    ->connectTimeout(5)
    ->requestTimeout(20)
    ->build();

Per-call request timeout

Override the request timeout for a single call without rebuilding the client.

$client->getHttpClient()->request("GET", $url, $headers, null, ["timeout" => 5]);

Bring your own HTTP client

When you pass a pre-built HTTP client, the SDK uses it as-is and applies none of the four knobs above. You own all transport behavior, including timeouts, retries, and response decompression.

$client = ClientBuilder::create()
    ->apiKey($apiKey)
    ->apiSecret($apiSecret)
    ->httpClient($myGuzzleClient)
    ->build();

SDK-specific notes

  • PHP: maxConnsPerHost and idleTimeout are enforced via libcurl's persistent multi-handle pool (CURLMOPT_MAX_HOST_CONNECTIONS and CURLOPT_MAXLIFETIME_CONN). They take effect only when the SDK client is reused across requests within a single PHP process: long-running runtimes such as Swoole, RoadRunner, ReactPHP, and CLI daemons. Instantiate the SDK client once and reuse it. Under PHP-FPM (and one-shot CLI scripts) the PHP process exits at the end of each request, so there is no cross-request pool to size; the per-call request and connect timeouts still apply. idleTimeout requires libcurl 7.80.0 (Nov 2021) or later.
  • Ruby: pooling relies on the net_http_persistent Faraday adapter. If a custom faraday_adapter: you pass cannot be configured, the SDK logs a warning and falls back to Faraday's default (non-pooling) adapter; the INFO log on construction reports the effective adapter.
  • Java: the environment variables STREAM_API_TIMEOUT and STREAM_API_CONNECTION_MAX_AGE (and their system-property equivalents io.getstream.timeout and io.getstream.connection.maxAge) still take effect and are folded into the default options.
  • .NET: on the escape-hatch path the SDK does not configure gzip decompression on your handler. Enable AutomaticDecompression = DecompressionMethods.GZip on your own SocketsHttpHandler if you need it.