My eventual goal is to create an SSE stream, but for now I just created a simple php file in the public folder of my Symfony project. The code in it has nothing to do with Symfony:
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
echo "data: 1nn"; flush(); sleep(1);
echo "data: 2nn"; flush(); sleep(1);
echo "data: 3nn"; flush(); sleep(1);
echo "data: 4nn"; flush(); sleep(1);
When I open my command line and run php public/sse.php
I get 1 line every second, just as I expect/trying to achieve.
However, when I run Symfony’s webserver (symfony server:start -d
) and then try to curl https://127.0.0.1:8000/sse.php
nothing happens for 4 seconds and then I see all the output at once. Seems like Symfony server is still buffering the output, but I don’t know why.
I tried:
php -i | grep output_buffering
returns “output_buffering => 0 => 0”- ran the curl command with –insecure, in case it got stuck on SSL issues
- to add
ob_end_flush
the first echo line
None of it worked. Any ideas?