Skip to content

SSE creates new connection #23

Description

@ljfreelancer88

I'm wondering the script below that I grabbed from Swoole website creates new connection or thread every couple of seconds and I don't like it. While yours is not which is I'm looking for. Sorry but this is not really an issue. Just want to ask or mentor me what's the idea to prevent SSE from creating new connection every couple of seconds. I want SSE to maintain that connection until that client closes or refresh the browser. Thank you in advance.

while(true):
        $data = "event: ping\n";
        $response->write($data);
        $curDate = date(DATE_ISO8601);
        $data = 'data: {"time": "' . $curDate . '"}';
        $data .= "\n\n";
        $response->write($data);
        $counter--;
        if (!$counter) {
            $data = 'data: This is a message at time ' . $curDate . "\n\n";
            $response->end($data);
            break;
        }
        Coroutine::sleep(3);
    endwhile;

Screenshot from 2021-03-02 08-18-35

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions