Skip to content

Add streaming responses and Server-Sent Events support (v3.6.0)#76

Merged
Thavarshan merged 1 commit into
mainfrom
feature/streaming-sse
Jul 21, 2026
Merged

Add streaming responses and Server-Sent Events support (v3.6.0)#76
Thavarshan merged 1 commit into
mainfrom
feature/streaming-sse

Conversation

@Thavarshan

Copy link
Copy Markdown
Owner

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 previous Response always buffered the whole body into memory.

What's new

  • StreamedResponse — the response.body equivalent. Pull raw chunks (stream()), newline-delimited lines (lines()), iterate the object directly, or fall back to a buffered Response via buffer(). Body is never read into memory up front.
  • EventSource + ServerSentEvent — a WHATWG-compliant text/event-stream parser that lazily yields events (multi-line data:, comments, id/retry persistence, [DONE] detection, chunk-boundary reassembly). Tracks lastEventId() / reconnectionTime().
  • stream() / sse() on ClientHandler and Client (via the RequestExecutor interface), plus fetch_stream() / fetch_sse() global helpers.
  • ContentType::EVENT_STREAM and NDJSON cases with isEventStream() / isStreamable().
  • PHP 8.5 added to the CI test matrix (Ubuntu/Windows/macOS).

Streaming is synchronous and intentionally bypasses the response cache, consistent with the library's existing sync-only caching behaviour.

Notes

  • Purely additive — no breaking changes. Targets a v3.6.0 minor release.
  • Docs: README feature, CODE_MAP.md entries, new docs/guide/streaming.md (+ sidebar), CHANGELOG.md v3.6.0 section.

Testing

  • 44 new tests (unit: ServerSentEvent, StreamedResponse, EventSource, ContentType; integration: StreamingTest end-to-end via a Guzzle mock handler, offline-safe).
  • Full suite: 518 tests pass. PHPStan clean at configured level. Duster lint clean. VitePress docs build succeeds.

🤖 Generated with Claude Code

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>
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for fetch-php canceled.

Name Link
🔨 Latest commit 1af03f1
🔍 Latest deploy log https://app.netlify.com/projects/fetch-php/deploys/6a5f47f05ddb9d00085fd10d

@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the breaking-change Changes the public API or observable behaviour label Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@Thavarshan
Thavarshan merged commit 6e0a200 into main Jul 21, 2026
42 checks passed
@Thavarshan
Thavarshan deleted the feature/streaming-sse branch July 21, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Changes the public API or observable behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants