Repository navigation
26 streaming request body - #27
Merged
Merged
Conversation
Adds opt-in streaming for request bodies, replacing the buffer-the-whole- body-then-dispatch path that holds Content-Length bytes per concurrent request. Targets the HttpArena `upload` profile where 1000 concurrent 20 MiB POSTs currently peak at ~20 GiB RSS. New API - HttpServerConfig::setBodyStreamingEnabled(bool) — server-wide flag, default false. When true, H1 and H2 parsers push DATA chunks into a per-request linked-list queue instead of accumulating into req->body. - HttpRequest::readBody(int $maxLen = 65536): ?string — drains one chunk; parks the coroutine on a per-request trigger event when the queue is empty; returns null at EOF. Internals (src/http_body_stream.c, include/http_body_stream.h) - New http_body_chunk_t linked list owned by http_request_t. - ZEND_ASYNC_NEW_TRIGGER_EVENT for wakeup — same pattern as the H2 stream write_event. - Disposed unconditionally from http_request_destroy. Integration - H1 on_headers_complete: flips req->body_streaming when the connection view advertises body_streaming_enabled (multipart still bypasses). - H1 on_body: streaming branch pushes via http_body_stream_push and skips both the pre-sized req->body buffer and the chunked smart_str accumulator. - H1 on_message_complete: streaming branch calls http_body_stream_close (EOF signal) instead of finalising body_builder into req->body. - H2 cb_on_data_chunk_recv: streaming branch enqueues without appending to stream->request_body_buf. - H2 finalize_request_body: streaming branch fires EOF and exits before the smart_str_extract path. HttpRequest::readBody also falls back to draining req->body once in non-streaming mode so handlers can use a uniform readBody() loop without branching on the server config. Measured impact (h2load -n50 -c50 -d 20MiB upload, release PHP, WSL2): - buffered: peak RSS 1170 MiB, 36 req/s - streaming: peak RSS 197 MiB, 100 req/s (~6x RSS, ~2.7x RPS) Tests - tests/phpt/server/h1/050-stream-request-body.phpt - tests/phpt/server/h2/050-stream-request-body.phpt Backpressure (llhttp_pause, deferred nghttp2_session_consume), HTTP/3, readBodyChunks() and the trichotomous mode lock from the plan are deferred to follow-up PRs — see docs/PLAN_STREAMING_INGRESS.md.
Pure comment / docstring changes — no behaviour change. - include/http1/http_parser.h: drop the misleading "naturally throttles" hint from the body_streaming block, mark the unused body_h2_*, body_h3_stream, body_paused fields and HTTP_BODY_QUEUE_WATERMARK as reserved-for-followup with explicit TODO(issue #26 backpressure) references. - src/http2/http2_session.c: rewrite the cb_on_data_chunk_recv streaming-branch comment to state correctly that nghttp2's auto window update is on by default and the queue grows up to max_body_size, and to point at the planned NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE follow-up. - src/http1/http_parser.c on_body: same TODO pointing at llhttp_pause / resume. - src/http_request.c readBody docstring: replace the vague "few KiB" H1 chunk estimate with the actual DEFAULT_READ_BUFFER_SIZE = 8 KiB, reword $maxLen note as a TODO so the eventual coalesce wiring is signalled in-source rather than only in the plan. 173/173 phpt green.
Closed
Contributor
CoverageTotal lines: 77.66% → 77.64% (-0.02 pp)
❌ Regression in touched files (> 1.0 pp drop)
Add |
The Fuzz embedded CI job linked fuzz_http1_parser / fuzz_h2_session without the streaming-body translation unit added in be96bac, producing undefined references to http_body_stream_push / _close / _dispose. Add the new file to HTTP1_SRC and H2_SRC so both binaries link again.
CHANGELOG entry covers the new HttpRequest::readBody() and HttpServerConfig::setBodyStreamingEnabled API plus the measured upload-RSS and throughput numbers. Buffered handlers are unaffected (A/B benchmarks show no regression beyond WSL2 noise). PHP_HTTP_SERVER_VERSION bumped to 0.5.0 — minor version bump because the new API is additive (no signature changes to existing methods).
EdmondDantes
added a commit
that referenced
this pull request
May 16, 2026
…rces on OpenSSL Three issues prevented a clean Windows MSVC build after the streaming request body merge (PR #27): 1. src/http_body_stream.c (new in PR #27) was missing from CMakeLists.txt. 2. src/core/http_connection_tls.c and src/core/tls_layer.c unconditionally include <openssl/bio.h> / <openssl/err.h> but were in CORE_SUBSYSTEM_SOURCES which compiled regardless of OpenSSL availability. Moved them to a TLS_SOURCES list that is only populated when find_package(OpenSSL) succeeds. 3. http2_conn_notify_emit (defined in src/http2/http2_strategy.c) was declared extern in http_connection.c without any HAVE_HTTP2 guard. Without nghttp2 the HTTP/2 sources are excluded and the symbol is undefined at link time. Added a static inline no-op fallback under #ifndef HAVE_HTTP2. Also added full nghttp2 detection (>= 1.57, mirrors config.m4) to CMakeLists.txt so the HTTP/2 sources are compiled when nghttp2 is present.
EdmondDantes
added a commit
that referenced
this pull request
May 16, 2026
Four issues prevented the unit test suite from building and running on Windows MSVC after the streaming request body merge (PR #27): 1. tests/CMakeLists.txt included `${PHP_SRC_DIR}/win32` as a system search directory, which caused PHP's win32/unistd.h and win32/time.h to shadow CRT system headers (same prohibition already in the main CMakeLists.txt — the test build was missing the matching guard). 2. tests/unit/CMakeLists.txt HTTP1_PARSER_SRC was missing four sources that http_parser.c and multipart_processor.c now depend on: - src/http_body_stream.c (new in PR #27, called by http_parser.c) - src/core/body_pool.c (body slab pool, called by http_parser.c) - src/http_rfc5987.c (called by multipart_processor.c) - src/http_param_parse.c (called by multipart_processor.c) The same rfc5987/param_parse pair was also missing from the standalone test_multipart_processor target. 3. test_compression_negotiate linked http_compression_negotiate.c but had no provider for http_compression_lookup (defined in http_compression.c, which in turn requires gzip/brotli/zstd vtables → external libs). Added tests/unit/compression/compression_stubs.c with a lightweight stub that returns a zero-initialized vtable for all three codecs so the selection logic is exercised without pulling in compression backends. 4. All unit test targets except Win32Compat and StaticDecoders were missing ENVIRONMENT_MODIFICATION to prepend PHP_DLL_DIR and CMOCKA_DLL_DIR to PATH, causing 0xc0000135 (DLL not found) at CTest run time on Windows. Added the matching property blocks (mirroring the existing Win32Compat pattern) for all remaining tests. Result: 7/7 tests pass under `ctest -C Debug`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.