SSE with nginx holds client connection

I’m trying to build a HTML5 “Server Send Event” with several clients.
In the mean time, I found out, that Nginx has to hold the client connection open, if currently no new data available to send to the client.
But I dont know how to handle it!

What is necessary to tell nginx to hold the connection open?
How can I use the open connections, when new data are available?

An example would be great.

Thanks for your support!

Hi @HGA ,

Take a look at proxy_read_timeout. As I see it, the loc conf should look roughly like this:

location /events {
    proxy_pass http://localhost:3000/events;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    proxy_cache off;
    proxy_read_timeout 1h; #keep conn open up to 1h
}

BTW, what backend server are you using (node.js/python/etc) to push events to clients?

Hi @route443, I want send the messages to push via PHP.
I’m sorry, but by knowledge about that is not good! I haven’t a good explainasion about how Symfony works together with Mercure. My current understanding is only that Mercure is a hub and clients only connect the hub and the holds the connections open.
Synfony sends the new message to the hub and the hub send it to all open connections.
I have a PHP script which knows, when new data are avaiable.

Where I have to install Mercure?
If I install Mercure, how can I define the url and the port, and is a different port neccessary?
My Synfony project I have stored under /var/www/html/sseUpdate.

So I think. the first step should be to install the hub and get the clients to the hub.

The next step to setup the Symfony project to controll the hub und last to send new data to Synfony.
That is only my guess!
What are found are only examples and not a good explanation, how the different parts working together.

Maybe you could advice me a good documentation.

For one example I could get running curl -N -v localhost/api/stream/stock/AAPL , but if I use `localhost/api/stream/stock/AAPL` in the local browser, I only get a white screen. I think that is due the fact, I have setup Nginx in the right way. But I can’t find where /api/stream/stock/AAPL is located.

So you now know, that I have to learn a lot.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.