We experimented with using Comet for a chat client variety once. The basic premise is that you open the connection (probably an AJAX request) to the web server and keep it open until
- Timeout expires (say 30 seconds)
- or there is some state of the application that requires sending data to the client.
At this point, the request is returned. If there is a payload, apply all that needs to be done, then repeat the request, which will begin the process.
The only serious drawback that we encountered was that many connections were open (just sitting there, waiting for an answer), we quickly exhausted the number of threads in Apache, and future ones were stopped. At this point, we refused the exercise (for other reasons), so we never considered possible corrections.
Another problem was to separate separate PHP threads in order to talk to each other, which is also not easy. As far as I remember, we ended up using something built on sockets, and each thread could talk to the other, given the unique identifier (I myself did not work on this bit, so I'm not sure if this is absolutely correct). In your case, you can check the runtime in a DB or file, and then return when the change occurs.
I would suggest that everything will evolve from the time we tried it (this was a few years ago), but I suspect that the general idea still remains, and the libraries used this.
source share