check if user got new message in the background?
im using comet to push new data to the user.
1: but i wonder how i shoul开发者_运维知识库d check if new data (new messages, new replies etc) is available?
should i in the php in the background use a while loop and sleep it for 1 min so it can check every one min if new data has come in?
or should i have a trigger in the database for this?
what available options are there?
2: and how can i actually check eg. if user got a new message with SQL? how should i set up "the system"?
1) I would use AJAX to ask for new messages from an opened user page. This way you do not need a script running on the background and only active users/pages need the results, so let them ask for it themselves.
2) If you send the date of the last message along with the AJAX request. It is fairly easy to check if the database contains newer messages with something like SELECT * FROM messages WHERE date > $last_message_date
精彩评论