Add streaming responses and Server-Sent Events support (v3.6.0)#76
Merged
Conversation
Introduce an unbuffered response path alongside the existing buffered API: - StreamedResponse: pull raw chunks (stream()) or newline-delimited lines (lines()) from the response body without reading it into memory; buffer() falls back to a materialised Response. - EventSource / ServerSentEvent: WHATWG-compliant text/event-stream parser that lazily yields events, for streaming LLM APIs and live feeds. - stream()/sse() on ClientHandler and Client (via RequestExecutor), plus fetch_stream()/fetch_sse() global helpers. - ContentType::EVENT_STREAM and NDJSON cases with isEventStream()/isStreamable(). - Streaming is synchronous and bypasses the response cache. Also add PHP 8.5 to the CI test matrix, and document the feature (README, CODE_MAP, docs guide, CHANGELOG for v3.6.0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for fetch-php canceled.
|
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
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.
Summary
Adds an unbuffered response path alongside the existing buffered API, bringing the "JavaScript fetch for PHP" experience up to date with the two capabilities modern HTTP clients are expected to have — streaming response bodies and Server-Sent Events — plus PHP 8.5 support.
Streaming is the single most-requested 2026 capability: every streaming LLM API (OpenAI, Anthropic, etc.) uses
text/event-stream, and the previousResponsealways buffered the whole body into memory.What's new
StreamedResponse— theresponse.bodyequivalent. Pull raw chunks (stream()), newline-delimited lines (lines()), iterate the object directly, or fall back to a bufferedResponseviabuffer(). Body is never read into memory up front.EventSource+ServerSentEvent— a WHATWG-complianttext/event-streamparser that lazily yields events (multi-linedata:, comments,id/retrypersistence,[DONE]detection, chunk-boundary reassembly). TrackslastEventId()/reconnectionTime().stream()/sse()onClientHandlerandClient(via theRequestExecutorinterface), plusfetch_stream()/fetch_sse()global helpers.ContentType::EVENT_STREAMandNDJSONcases withisEventStream()/isStreamable().Streaming is synchronous and intentionally bypasses the response cache, consistent with the library's existing sync-only caching behaviour.
Notes
CODE_MAP.mdentries, newdocs/guide/streaming.md(+ sidebar),CHANGELOG.mdv3.6.0section.Testing
ServerSentEvent,StreamedResponse,EventSource,ContentType; integration:StreamingTestend-to-end via a Guzzle mock handler, offline-safe).🤖 Generated with Claude Code