Skip to content

Commit abbe5fa

Browse files
committed
[HttpFoundation] Flush after each echo in StreamedResponse
1 parent 5a69e81 commit abbe5fa

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

StreamedResponse.php

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function setChunks(iterable $chunks): static
5656
$this->callback = static function () use ($chunks): void {
5757
foreach ($chunks as $chunk) {
5858
echo $chunk;
59+
@ob_flush();
60+
flush();
5961
}
6062
};
6163

Tests/StreamedResponseTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ public function testConstructorWithChunks()
3030
$chunks = ['foo', 'bar', 'baz'];
3131
$callback = (new StreamedResponse($chunks))->getCallback();
3232

33-
ob_start();
33+
$buffer = '';
34+
ob_start(function (string $chunk) use (&$buffer) {
35+
$buffer .= $chunk;
36+
});
3437
$callback();
3538

36-
$this->assertSame('foobarbaz', ob_get_clean());
39+
ob_get_clean();
40+
$this->assertSame('foobarbaz', $buffer);
3741
}
3842

3943
public function testPrepareWith11Protocol()

0 commit comments

Comments
 (0)