Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SSE creates new connection #23

Open
ljfreelancer88 opened this issue Mar 2, 2021 · 0 comments
Open

SSE creates new connection #23

ljfreelancer88 opened this issue Mar 2, 2021 · 0 comments

Comments

@ljfreelancer88
Copy link

ljfreelancer88 commented Mar 2, 2021

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant