Skip to content

Prevent EmitterException when output buffer has content#73

Merged
tommitchelmore merged 4 commits into
masterfrom
fix/issue-72-response-emitter
May 20, 2026
Merged

Prevent EmitterException when output buffer has content#73
tommitchelmore merged 4 commits into
masterfrom
fix/issue-72-response-emitter

Conversation

@tommitchelmore
Copy link
Copy Markdown
Collaborator

@tommitchelmore tommitchelmore commented May 20, 2026

If headers have not been sent but the output buffer is not empty, Laminas SapiEmitter throws an EmitterException. This commonly happens in WordPress when plugins (like Gravity Forms) leak output early.

We now detect this scenario, clean the buffer, and echo its content before calling SapiEmitter, ensuring all previous output is preserved while allowing the PSR-7 response to be emitted correctly.

If headers have not been sent but the output buffer is not empty,
Laminas SapiEmitter throws an EmitterException. This commonly happens
in WordPress when plugins (like Gravity Forms) leak output early.

We now detect this scenario, clean the buffer, and echo its content
before calling SapiEmitter, ensuring all previous output is preserved
while allowing the PSR-7 response to be emitted correctly.
Copy link
Copy Markdown
Collaborator Author

@tommitchelmore tommitchelmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - one minor tweak. I've tried these changes in a downstream project and they seem to make the emitter much more resilient as intended.

Comment thread src/Http/ResponseEmitter.php Outdated
Co-authored-by: Tom Mitchelmore <tommitchelmore@outlook.com>
@tommitchelmore tommitchelmore merged commit 6922be5 into master May 20, 2026
6 checks passed
@tommitchelmore tommitchelmore deleted the fix/issue-72-response-emitter branch May 20, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResponseEmitter::emit() breaking Gravity Forms "Page" confirmations

3 participants