how to implement facebook like notification?

荒凉一梦 提交于 2019-11-28 14:39:33

问题


I am trying to implement a Facebook-like live notifications system to notify users whenever someone adds them as friend, like their post or posts replies to their comments.

All the database and PHP part is done, but I can't figure out how to implement it like Facebook has.

Whenever someone likes/comments on your post in Facebook the light blue box appears at the bottom left corner of the screen. This happens as soon as someone hits like button or posts comment in Facebook. I would like to know what I should do to implement this.

Using YUI or any JavaScript framework I can query a database table after n seconds to check for notifications. This method is too heavy.

I was wondering if there is any server side mod or scripting can be done so that whenever there is new notification entry in my database table the server will tell that particular client. That way unnecessary request calls from client to server will be avoided completely and system can work efficiently for website with more than 50,000 users online at a time.

How can I achieve this?


回答1:


You should look into COMET techniques, such as forever frame (tutorial) and long polling. That allows you to have a form of a server->client push communication.




回答2:


I am really surprised nobody has mentioned PubNub and Pusher

These two (competitors) are building infrastructure which allows for realtime notifications, just like Facebook.




回答3:


Facebook notification




回答4:


You basically set a request up, like callng the service that asks your server/db for the notifications of that user. You may do a while loop that retries if theres no notification (maybe Thread.Sleep in between searches). Your js request will timeout, then you can call the function again in timeout. This means long polling afaik




回答5:


The only way to do it is to have some sort of mechanism (e.g. Javascript) to repeatedly poll the server for updates. Doing server pushes to web browsers isn't possible.



来源:https://stackoverflow.com/questions/5359773/how-to-implement-facebook-like-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!