phpstreamserver icon indicating copy to clipboard operation
phpstreamserver copied to clipboard

Blocking I/O

Open root-aza opened this issue 5 months ago • 4 comments

https://github.com/phpstreamserver/phpstreamserver/blob/main/src/Symfony/src/Http/AmpHttpFactory.php#L21

root-aza avatar Aug 13 '25 12:08 root-aza

Thanks for highlighting this. The issue wasn't even blocking IO, but buffering itself. StreamedResponse was buffered and only flushed at the end, instead of streaming progressively. I've removed buffering, so the response now streams directly to the client as it's generated. Changes are here: https://github.com/phpstreamserver/phpstreamserver/commit/4da8bd4ee917e88455ad79b2fe4dd4d4bc0439f8.

luzrain avatar Aug 16 '25 15:08 luzrain

Thanks for highlighting this. The issue wasn't even blocking IO, but buffering itself. StreamedResponse was buffered and only flushed at the end, instead of streaming progressively. I've removed buffering, so the response now streams directly to the client as it's generated. Changes are here: 4da8bd4.

It seems to me that the problem is much worse, in response itself echo is used, and echo is also a blocking I/O. So it's better to make separate responses, where there won't be such problems. Yes, it's BC, but there won't be any extra overhead.

root-aza avatar Aug 16 '25 16:08 root-aza

I agree, a separate StreamedResponse that doesn't rely on echo under the hood could be a better option.

luzrain avatar Aug 16 '25 17:08 luzrain

Or is there another option, to make a PR in symfony/http-foundation and isolate echo

P.S. By the way, we also encountered similar problems within the new RoadRunner + Symfony integration, so for now we decided to make separate responses.

root-aza avatar Aug 16 '25 17:08 root-aza