-
Notifications
You must be signed in to change notification settings - Fork 297
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
Response doesn't support stream-based output #109
Comments
@albertcht can you open a PR to show the changes needed? |
Sure, I will submit a PR to show the changes needed for stream-based output. |
It would be ideal if there were a way to access the current My use case is streaming large JSON objects, which currently is done using a JSON generator calling I'd be happy to assist with a PR, but I wasn't sure where architecturally in Octane this would go. Do any of:
make sense? |
In #138 this was referenced; https://github.com/hhxsv5/laravel-s/blob/master/src/Swoole/DynamicResponse.php Does that help? |
Hi @barryvdh, yes lines https://github.com/hhxsv5/laravel-s/blob/master/src/Swoole/DynamicResponse.php#L24-L26 do work to capture the output from The reason an application would choose to use Symfony's I think the most robust technique would allow the app to call a Something along the lines of: https://gist.github.com/27pchrisl/6dbe0993b2423531b4afaf406a05224d In this example if you were an Octane-aware app that really needs streaming, you'd be pointed at replacing your I'm not sure how Roadrunner works internally, but |
Hi @27pchrisl, Indeed, the buffer fetching solution doesn't cover large output case. I am also thinking if there's a way of being compatible with non-Swoole environment in large stream output. My PR will handle the most buffer cases first, and then try to take care of large output later. More discussions about that are welcomed. |
Basis case is here: #151 |
I think it's not really easy to capture the output non-blocking. You can provide a callback to ob_start, but I guess if you actually want to use a streaming response in swoole, you would need to create a StreamResponse which uses the SwooleResponse as callback parameter, so you can just do |
Indeed, haven't come up with a good idea for handling that without providing swoole response instance to stream response. |
Whoops, by default it's not chunked. So the 2nd param to ob_start needs to be > 0. Luckily @themsaid fixed that in #153 :) |
I think because true streaming responses are a bit specialist, and this To ensure the |
Well I was wrong because if you use a chunk parameter with the ob start callback, it does flush correctly to the Swoole Response. See the comments on the PR. |
That's cool! I didn't notice there's a 2nd param for that purpose. |
Had to look into it - php/php-src@888f376 Thanks @barryvdh ! |
I'm "streaming" really big files, like > 4GB in size. And it fails at some point because it looks like Swoole is buffering the whole output and at some point it has not enough memory. Any solution to this? |
Oh, I get it. It's |
Description:
Most of PHP's output usages like
echo
,var_dump
output its content to buffer. In Swoole's case the result will print on console instead of web.It seems this partial code in
SwooleClient.php
refers from hereoctane/src/Swoole/SwooleClient.php
Lines 153 to 178 in 08537a7
output
property doesn't exist in symfony's response object. Theoutput
property is set from here inswooletw/laravel-swoole
.Symfony\Component\HttpFoundation\StreamedResponse
doesn't supportgetContent
andsetContent
for setting output content, so I fetch buffer output and set the result to response'soutput
property manually.If Octane is going to support stream output, it needs to use
ob_
functions to catch stream content as well.Many thanks to the official team for integrating Swoole into Laravel!
Steps To Reproduce:
The text was updated successfully, but these errors were encountered: