Reputation: 71
For a while I've been playing with the idea of long polling for my notification system, but i've never been able to think of a way to make it more efficient for my backend.
Most implementations I have seen hold the connection open, and the php queries the database server every few seconds to see if new data has been aded. This strikes me as no better than having the javascript repetitively poll the server.
In either case I have my database servers being hit tens thousands of times, which is understandably not particularly desirable.
Are there any systems in place that could 'alert' the executing/sleeping long polling script to the new data?
Upvotes: 6
Views: 1285
Reputation: 37788
Single system
If your application is the only system that changes the database, then you can trigger your listeners only when your application performs changes (ideally only for changes to the entities which are interesting for each listener).
Multiple systems
In the case of multiple systems accessing/changing the database, you can either
or if you don't want to do that (I usually avoid it), you can either
or if that's not possible
Upvotes: 2