but I can't make it work in fuel. I have been fighting with the Response object, but I can't get fuel to send more than 1 response with a single controller call. If I put the response->send() in the while loop, it does not work. It only works with return $response; or even with die(). Then it sends all accumulated events at once.
I have tried REST controller and base/template controller.
What would be the proper way to do this within fuel?
Now what I have is the client polling the server (running the controller once and dying/returning), but this is not what server events should do.
You can't do that in Fuel, it's a framework made for request/response operations, it's not a continues listener which you need for this kind of implementation.
It requires a streamed response to be able to send continues updates, which Fuel v1 does not support.
Please note that this means a PHP process running for every client, which is not very efficient, and may cause your webserver to overload if you have more than a few clients. Also, create a solution to terminate the while loop, otherwise the processes run forever, even when the client is gone. And then there's PHP's execution timeout, which will abort the script unless you have disabled it.
You might also want to have a look at Symfony's StreamedResponse which is part of it's HTTP foundation package, and which is designed to handle this kind of scenario's.