0

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.

user1614526
  • 474
  • 1
  • 4
  • 13

1 Answers1

3

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.

Edit:

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:

http://socket.io/

What MySQL drivers are available for node.js?

Sharing data between php and node.js via cookie securely

Authenticate user for socket.io/nodejs

Socket IO send to specified user ID

Community
  • 1
  • 1
Aurimas Ličkus
  • 9,886
  • 4
  • 24
  • 26