As in the title described i want to send some data in runtime from Symfony 6 with StreamedResponse() class.
The docs example looks like this:
use Symfony\Component\HttpFoundation\StreamedResponse;
$response = new StreamedResponse();
$response->setCallback(function () {
var_dump('Hello World');
//ob_flush();
flush();
sleep(2);
var_dump('Hello World');
//ob_flush();
flush();
});
$response->send();
The above example gives the complete output at the end of the script. Some other ideas were to put ob_flush() before flush() but this doesnt change anything.
in my php.ini was output_buffering = 4096
Is there another place to change something to send messages at runtime?
Edit (1)
Here is the additional try from a comment with the same result: @ob_end_clean();
ini_set('output_buffering', 0);
$response = new StreamedResponse();
$response->headers->set('X-Accel-Buffering', 'no');
$response->headers->set('Content-Type: ', 'text/event-stream');
$response->headers->set('Cache-Control', 'no-cache, must-revalidate');
$response->setCallback(function () {
echo 'Hello World';
//ob_flush();
flush();
sleep(3);
var_dump('Hello World');
//ob_flush();
flush();
});
$response->send();
return $response;
The response headers are:
Cache-Control: must-revalidate, no-cache, private
Content-Type:: text/event-stream
Date: Wed, 31 May 2023 13:54:51 GMT
Set-Cookie: PHPSESSID=h26uhmnc7nq6sibu6ed566k9oe; path=/; secure; HttpOnly; SameSite=lax
X-Accel-Buffering: no
X-Powered-By:PHP/8.1.6