Skip to content

Fix connection pool reuse: HTTP/1.1 is persistent by default (RFC 7230)#46

Open
owner888 wants to merge 1 commit into
workerman-php:masterfrom
owner888:fix-keepalive-recycle
Open

Fix connection pool reuse: HTTP/1.1 is persistent by default (RFC 7230)#46
owner888 wants to merge 1 commit into
workerman-php:masterfrom
owner888:fix-keepalive-recycle

Conversation

@owner888

@owner888 owner888 commented Jul 3, 2026

Copy link
Copy Markdown

What

Fix connection pool reuse: treat HTTP/1.1 connections as persistent by default (RFC 7230 §6.3), instead of requiring both request and response to carry an explicit Connection: keep-alive header.

Why

recycleConnectionFromRequest() currently closes the connection unless both sides literally sent Connection: keep-alive:

if ('keep-alive' !== $request_header_connection || 'keep-alive' !== $response_header_connection || ...) {
    $connection->close();
}

Real-world HTTP/1.1 servers (nginx, Google frontends, most CDNs) omit the Connection header because persistence is the protocol default. As a result the pool closes every connection after each response and never actually reuses any — every request pays a fresh TCP + TLS handshake.

Per RFC 7230 §6.3, an HTTP/1.1 connection persists unless either side explicitly signals close.

Benchmark

Streaming requests against generativelanguage.googleapis.com (20 samples each, time-to-first-byte):

median min
before (no reuse, handshake every request) 0.934s 0.821s
after this fix 0.803s 0.645s

~130ms saved per request once the pool warms up.

Notes

  • Transport-level failures (no response) and non-1.1 protocols still close the connection, as before.
  • If a server does close the socket unilaterally, process() already handles it via the existing getStatus()reconnect() path, so pooling a to-be-closed connection is safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant