Laravel-swoole: StreamedResponse not working

Created on 8 May 2018  ·  5Comments  ·  Source: swooletw/laravel-swoole

Please answer these questions before submitting your issue. Thanks!

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
    PHP 7.2.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 30 2017 13:58:33) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.2.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.18.0~linux-x64-non_zts72, https://blackfire.io, by SensioLabs

swoole

swoole support => enabled
Version => 2.1.3
Author => tianfeng.han[email: [email protected]]
coroutine => enabled
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async http/websocket client => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

  1. Please provide your Laravel/Lumen version.
    Laravel 5.6.21
  1. Which release version of this package are you using?
    2.3.4

  2. What did you do? If possible, provide a recipe for reproducing the error.
    SomeController@show

$response = new \Symfony\Component\HttpFoundation\StreamedResponse(function() {
    echo 'test';
}, 200, []);
return $response->send();
  1. What did you expect to see?
    The string "test" being echoed. (code works with nginx/php-fpm)

  2. What did you see instead?
    0 bytes are returned and server returns a 500.

bug fixed

All 5 comments

Hi @mfauveau ,

Thanks for your bug report. I'm working on fixing it.

Hi @mfauveau ,

I fixed it in the commit https://github.com/swooletw/laravel-swoole/commit/e63e9d3198398f749e97cc6ce97924c0125a964c, and will merge into the next release.

However, the streamed response is synchronous now, so it's not recommended to do some heavy output in the response.

I am considering to make it asynchronous in the future.

This fix has been merged into the newest release.

Hi @albertcht, thanks for the fixing this so quickly! What would it take to make it asynchronous?

Hi @joecohens ,

Basically you can push stream response to a Swoole task queue. The task delivering is totally asynchronous, but the process in task worker is still synchronous. At least it will not block the normal worker process.

Or you can create a process for stream response, and bind it to Swoole event, after the process is done, destroy the event binding. But in this way will consume more CPU resource.

So I'm still trying to find a balance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

storyn26383 picture storyn26383  ·  5Comments

junshenshi picture junshenshi  ·  3Comments

amcsi picture amcsi  ·  3Comments

codercms picture codercms  ·  5Comments

jiangjiang0228 picture jiangjiang0228  ·  8Comments