Implementing server-sent events is on the face of it quite a simple task. Borrowing the examples in the Mozilla documentation the client side code would be along the lines of
var evtSource = new EventSource("ssedemo.php");
evtSource.onmessage = function(e){//do stuff with e.data here}
What I have difficulty understanding is what happens server side. The things that puzzle me
- So you want to keep sending out events from ssdemo.php means that you need to run it in a loop and let it sleep when it isn't sending
- But by default Apache is setup to kill scripts that take "too long" to execute so this cannot be an infinite loop unless you setup that script run that way
- If I have 10 users who come in requesting the same SSE service (ssdemo.php) would it then mean that I would have 10 instances of that looped script?
I suspect that my understanding of how the server side code works, should be coded is either flawed or naive or both. I would much appreciate any pointers to the right way to do this.