Take the 2-minute tour ×

I am working on a project where i am trying to build an interface like If user is logged in and in between that if sever has any message for that user then the user will get notify immediately (Like facebook ) so for i am going through websockets but confused from where should i start ? please suggest me some basic ideas ?

I am using PHP as a language for implementation

I'm looking for advice at the moment on achieving real-time notifications using a mix of PHP, NodeJS and socket.io. At the moment I have done next to nothing with Node and socket.io so I'm at a loss with the best way to achieve this. I've done some basically listening and what not but nothing extreme.

For now my questions are:

  1. How will socket.io know of new notifications, should PHP be responsible for sending the data (say a post was created) to socket.io and from there broadcasting to connected clients?
  2. How does socket.io know which clients want the notifications?

I'm really not sure what else. This is all a bit much for me at the moment. I just can't get my head around how the notifications will be distributed.

Any advice would be greatly appreciated. I don't expect a detailed walk through, just a push in the right direction or some knowledge on how it all meshes.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Start from reading what is websockets, how they work, what browser support. The internet is full for this information.

For php implementation, take a look at the http://socketo.me/. PHP is not best suited for socket communication. I would use nodejs+socket.io and php for 'regular stuff'. Don't be afraid to mix technologies, there is no hammer for all problems.


If you don't know nodejs then it could be hard, but it's worth your time to learn it.

Some ideas:

You can create table with notifications on your database, then if some event acccurs, ex. post added add record there (like number of new posts, and user_id), then from nodejs side connect to database fetch database and look for notifications for current user.

Then nodejs notifies listening clients about changes (socket.io)

If user reviews new posts update counter to 0, (something similar what facebook does when you have new message), and then nodejs will know that there are no new post, so nothing to notify.

The hardest part is to get current user session.

Some related:


Node.JS and MySQL drivers

Sharing data between php and node.js via cookie securely

Authenticate user for socket.io/nodejs

Socket IO send to specified user ID

share|improve this answer
anyway i have the basic idea of websockets but merging these all technologies will be headache for me –  user1614526 Aug 31 '12 at 6:35
well it's not that difficult, but if you prefer php, socket.me should be ok. –  Aurimas Ličkus Aug 31 '12 at 6:51
please provide me any working example i am frustrating now just because of this problem –  user1614526 Aug 31 '12 at 8:55

Your Answer


