Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbuffered streaming output #3323

Open
Bilge opened this issue May 20, 2024 · 1 comment
Open

Unbuffered streaming output #3323

Bilge opened this issue May 20, 2024 · 1 comment

Comments

@Bilge
Copy link

Bilge commented May 20, 2024

Hi, I am writing directly to php://output in my action because I do not want to buffer (large) output in memory or on disk. However, Slim quietly elects not to send headers in this case, because ResponseEmitter::emit notices headers_sent now returns true. How can I still send custom headers whilst writing output directly to PHP's output stream?

Note: Symfony supports this with StreamedResponse.

@Bilge
Copy link
Author

Bilge commented May 21, 2024

The solution is this old 2015 implementation of CallbackStream. Current implementations in either psr7examples or laminas-diactoros will not work. The former won't because it uses output buffering (lol why) and the latter doesn't because it implements getContents() in lieu of read(), but Slim's ResponseEmitter calls read() instead of getContents().

I might urge the maintainers to include the only working implementation hidden away in that lone gist before it gets lost to time.

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

No branches or pull requests

1 participant