-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Proposal] Support no output buffering at all #2481
Comments
I think that would break the ability for middleware to replace or alter the response. I think a generator as a body would be a good fit here. If Slim could be altered to allow a generator as well as a class NonBufferedAction
{
public function __invoke(Request $request, Response $response): Response
{
return $response
->withBody(function (): Generator { // won't work now, as Slim expects a StreamInterface instance
foreach (['alpha', 'beta', 'gamma', 'delta'] as $data) {
sleep(1);
yield $data;
}
});
}
} |
I like the idea of a specialised StreamInterface. Implementing this will also address Server Sent Events support (#1959). |
I submitted a PR with a possible implementation, but I'd like to have a bit of input from the mantainers and/or other community members before doing the rest of the gruntwork (mostly documentation). |
Use case
Adding the ability to completely disable output buffering would empower the developer to push content to the user agent while still processing an HTTP request (i.e. while still inside the callback or Action class). This would allow, for instance, to give real-time feedback at every iteration of a long-running loop.
The following is a minimal demonstration in pure PHP that can be served with the builtin webserver to see the effect firsthand:
Current status
Slim 3 has an
outputBuffering
setting whose legal values arefalse
,'append'
and'prepend'
(default'append'
). However,false
seems to simply instruct the framework to neither prepend nor append strayecho
's to the PSR7 response.As far as I understand, Slim does not currently support this behaviour.
Proposed API
I believe that the cleanest way to add this feature would be through a new specialized implementation of the
StreamInterface
that would handle all the details under the hood in itswrite
method. The former sample could be then rewritten like this:What are yer thoughts?
The text was updated successfully, but these errors were encountered: