Notifications via socket.io on php site

I am building a website in PHP that handles the sessions in Redis in JSON format.

This way the session can be accessed by both the PHP interpreter and a node.js server.

What I am trying to do is now to add notifications in said website; the procedure I was thinking of is the following: (just figure it as a simple friend request to simplify it all)

  1. user A sends friend request.
  2. PHP uses cURL to say to node.js service to send notification
  3. user B gets a notification because he is connected to node.js via socket.io

What are the general guidelines to achieve this? Because it looks clear to me that if user A and B are in different servers, it will be impossible to scale horizontally;

Thanks in advance.

Sounds like a you could make use of Web Sockets here with a Publication / Subscription protocol, architecture.

You get Server client functionality with web sockets. Node is a perfect choice for a websocket server, lots of small IO. See http://en.wikipedia.org/wiki/Web_sockets

I'm wouldn't think if the shared session is required for php - node communication, just have your clients push requests through the socket and handle the reposes as needed.

I think the approach you propose sounds quite reasonable. However, instead of doing a direct request to the service, you could consider using a message queue (zeromq, rabbitmq, whatever) which would allow you to scale it more easily as you can easily add logic to the queue processing to pass the message to the correct node instance.

I managed to get 1400 concurrent connections with socket.io on a cheap VPS with no special configuration so even with no tricks it should scale quite well. In my case most of these connections were also sending and receiving data almost constantly. It could probably have handled more than that, 1400'ish was simply the max number of users I happened to get.

Though I'd worry more about getting all those users first ;)

Use Redis's built in pub-sub capability. When the PHP server gets a request, it publishes it to a channel set up for that purpose. Each of your node servers subscribes to that channel and checks if the user involved is connected to it. If so, it sends the notification via socket.io. As a bonus, you avoid an extra network connection and your overall logic is simplified.