0
votes

I have a very simple PHP Server Side Events controller (simplified for this question):

    $response = new StreamedResponse(function() {
        while (true) {

            if(connection_status() != CONNECTION_NORMAL) {
                die();
            };

            echo 'data: '. "\n\n";

            ob_end_flush();
            flush();

            sleep(1);
        }

    });

    $response->headers->set('Cache-Control', 'no-cache');
    $response->headers->set('Content-Type', 'text/event-stream');
    return $response;

When I call that from my Angular app it opens and closes the connection for every loop, so it looks like this:

enter image description here

Something has changed because previously I just saw one request and a spinning icon for that request and then the data stream would update every second.

What could cause this?

1
the while(true) and sleep(1) maybe? what do you expect it to do? cuz it's doing exactly what the code saysSalim Djerbouh
As I understand it the stream is opened and then every second I run my code to check if new updates should be pushed through the stream.Christoffer

1 Answers

0
votes

I removed ob_end_flush(); and it kept the connection opened as expected.