Reputation: 570
I am creating a web application, and I am in need of some way to do the following in jQuery and PHP:
I have tried Long-polling methods on Google with jQuery but they pretty much do the same. This is the sort of thing I'm looking for.
Any help is appreciated.
Thanks.
Upvotes: 1
Views: 883
Reputation: 53146
Just as a precursor, if you do go down that route, you should also make sure that your sessions are not locked per request. You could easily hit a situation when a session gets locked when you make the request.
As a better option, you might want to just work on a "heartbeat" like solution, by requesting the PHP page every 30 seconds. (which is similar to what StackOverflow) do hear to notify you when a new message has come in.
Even better than that, would be to use WebSockets in node.js. You could even have PHP notify node.js when something "new" comes in, like you say, so that it is always accurate, and you don't have some PHP script constantly running.
WebSockets via socket.io
Upvotes: 1
Reputation: 3460
Have you tried a settimeout in JS that starts over every time PHP returns no updates?
So:
checkPHP()
).settimeout(checkPHP,5000);
!= 0
, do your thing.!= 0
Upvotes: 0