32

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?

Jonas G. Drange
  • 8,749
  • 2
  • 27
  • 38
Vinay Jeurkar
  • 3,054
  • 9
  • 37
  • 56

5 Answers5

23

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.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • thanks a lot for your reply.. i am going to learn that as soon as possible. are there any similar ways available? so that i can choose amongst the best. also what could a facebook might be using? because it is not just notification system i will be using this comet like thing for but also whenever some user posts reply to user's comment etc. the message will be attached at the bottom very quickly just like facebook.. thank you very much again. – Vinay Jeurkar Mar 19 '11 at 03:30
  • @Forte, the other major techniques are listed in the article. They include `multipart/x-mixed-replace` and various forms of polling. – Matthew Flaschen Mar 19 '11 at 03:50
  • @Matthew: Then i guess content management system like **Drupal** supports these kind of stuffs. So then they have been implemented this COMET techniques? – Ant's Mar 19 '11 at 03:50
  • @Anto, I don't know much about Drupal, but I wouldn't be surprised. – Matthew Flaschen Mar 19 '11 at 03:55
  • @MatthewFlaschen both links are dead. you can replace them with [this](https://web.archive.org/web/20160318121755/http://cometdaily.com/2007/11/05/the-forever-frame-technique/) and [this](https://web.archive.org/web/20110717051129/http://www.webreference.com/programming/javascript/rg30/) – Binar Web Feb 05 '20 at 09:07
6

I am really surprised nobody has mentioned PubNub and Pusher

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

Samudra
  • 1,013
  • 1
  • 14
  • 21
2

Facebook notification

Community
  • 1
  • 1
Dead Programmer
  • 12,427
  • 23
  • 80
  • 112
0

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

Romain Francois
  • 17,432
  • 3
  • 51
  • 77
-11

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.

Bleaourgh
  • 29
  • 1