Skip to content

Add stream responses - #185

Open
tryvin wants to merge 11 commits into
brefphp:masterfrom
EightSystems:add_stream_responses
Open

tryvin wants to merge 11 commits into
brefphp:masterfrom
EightSystems:add_stream_responses

Conversation

@tryvin

@tryvin tryvin commented Jul 21, 2025 •

Copy link
Copy Markdown

With Lambda Function URLs supporting RESPONSE_STREAM, we can make response()->stream() work as intended, streaming content as it is received.

To keep Octane's request lifecycle alive while the body is being streamed, the request is handled inside a fiber: the request is suspended when a response is produced, and resumed once the body has finished streaming.

This PR cleans up that support and makes it robust:

  • a single code path suspends, resumes, and terminates fibers in the Octane client (deduplicated respond()/error(), safe termination after every invocation)
  • streamed bodies are extracted in one place: generator callbacks work even without a return type declaration, echo-style callbacks are captured instead of lost, and file downloads are streamed chunk by chunk
  • streaming mode detection mirrors the FPM runtime (BREF_STREAMED_MODE, with BREF_STREAM_NO_FIBER to opt out)

This uses the new HttpResponse Generator body support from bref/bref.

Depends on: brefphp/bref#2168

@tryvin

tryvin commented Jul 21, 2025

Copy link
Copy Markdown
Author

@mnapoli PHP stan fixed.

tryvin added 4 commits August 18, 2026 21:59
- Fix undefined Bref::doesStreamingSupportsFibers() call: detect
  streaming mode via BREF_STREAMED_MODE and honor the
  BREF_STREAM_NO_FIBER opt-out, mirroring the FPM runtime
- Extract the inline event subscriber into a FiberTerminationSubscriber
  that resumes the suspended fiber once the invocation has ended
- Deduplicate respond()/error() into handOffResponse() and only suspend
  when running inside the request fiber
- Terminate fibers safely: resume only while suspended and clear the
  fiber state upfront
- Extract response body handling into ResponseBodyExtractor: stream
  generator callbacks even without a declared return type, capture
  echo-style streamed callbacks, and stream BinaryFileResponse content
  chunk by chunk in streamed mode
- Add tests for the response body extractor
@tryvin

tryvin commented Aug 18, 2026

Copy link
Copy Markdown
Author

@mnapoli updated here too!

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.

2 participants