开发者

how to detect incoming chat message?

开发者 https://www.devze.com 2023-01-05 17:06 出处:网络
I\'m using PHP, AJAX, a MySQL database, and a lot of jQuery to prototype web-based chat system (similar to Facebook Chat). I\'m stuck on how to \"listen\" for incoming chats... when to know someone is

I'm using PHP, AJAX, a MySQL database, and a lot of jQuery to prototype web-based chat system (similar to Facebook Chat). I'm stuck on how to "listen" for incoming chats... when to know someone is trying to chat me... and to know that it is a new chat, not an existing chat.

Right now, I'm polling to see if there has been new insertions in the database tables but it seems very inefficient... a lot of overhead for the server.

Is there a way to receive a notification when, for example, a row has been inserted in a table in a MySQL database so that instead of having constantly poll, I can just be notified and then go look at what as inserted?

If there is a better and more efficient way to cre开发者_StackOverflowate this one-on-one chat relationship, please give me some suggestions.

Thanks, Hristo


You have to use polling, but you can use a technique called Comet which involves long-polling, i.e. sending out an ajax request that will be held by the server until a chat request comes in.

http://en.wikipedia.org/wiki/Comet_(programming))


I think polling is the only way for JavaScript to be pushed server side changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消