I'm not sure this is even a valid method? The server.php is just running and running, and while I believe that the time spend sleeping is not counted towards the total run time (if it is counted as a 'system call', there is probably a limit to how long your scripts are allowed to run (default it is 30 seconds). So while the bulk of the time is spend in sleep, there is still a limit: php.net/manual/en/info.configuration.php#ini.max-execution-time
–
NanneSep 6 '12 at 10:14

I am aware of the time limit, it wont be an issue. Its more about getting this first step rite.
–
Good-byeSep 6 '12 at 10:19

Seems to me like you are using the wrong tools for the job... have a look at: nodejs.org
–
George ReithSep 6 '12 at 11:00

Just a note: Ive found allot of examples in the wild where the guys are simply reconnecting to there server.php or stream.php file. Thats wrong. The connection should stay open to steam in data as it happens. If you keep reconnecting, your doing polling and that can be done via ajax, your defeating the purpose of server-sent-events.
–
Good-byeSep 6 '12 at 14:25

@Derrick Connecting and reconnecting is bad when your server-side language is designed to handle running and running, but unfortunately PHP is not. See this link: software-gunslinger.tumblr.com/post/47131406821/… ... A better way to go, potentially, is to keep a connection open for 10-30 seconds, then die and let the client reconnect.
–
Don McCurdySep 10 '13 at 21:31

@Derrick, your suggested ob_end_flush(); line got me close, but in more complex PHP than hello world code, I was still getting unwanted reopens on my SSE connections (I still don't fully understand why ob_end_flush() was doing that to me). So here's the pattern I'm now using (otherwise identical to your stream.php). In English, I'm turning off PHP output buffering before entering my infinite loop: