Real-time web apps in PHP
Posted 07 July 2011 - 06:42 AM
Currently I'm developing a web app for online collaboration. One of the key features is real-time responsiveness - i.e. when someone posts something, others get the new post instantly.
I do not consider old-school stuff like setting timeout on a client. At the moment I think that socket.io is pretty much what I need. But I have a doubt whether the tandem "php+socket.io" is viable. For example, how do I make them communicate with each other? How do they share the auth session?
Does anybody have experience in this field? Your experience is very valuable to me.
Posted 07 July 2011 - 06:53 AM
To communicate between php and web sockets I suppose you will need some comet solution. We did it on this way:
1. Have Redis (pub/sub feature) to send/retrieve messages (channel No is user ID)
2. Have PHP to send notifications into Redis when something happen
3. Have Node.js app listen all channels and send notification to web sockets
How to identify user:
1. After user login we added to Redis hash pair: sessionID => userID
1. After user connected to socket, it send auth command to node.js with session ID.
2. Node.js check hash in Redis for sessionID and get userID.
3. Node.js subscribe connection to userID channel
Posted 07 July 2011 - 07:34 AM
Node.js + socket.io
Have no serious problems.
Honestly, can't tell you exactly because we haven't opportunity to run with highload yet. But I assume we wouldn't have any problems with ~100 connections (or maybe even with 1k, because node.js + redis is very fast).
Also please note, that you could easy to scale node.js application by just copping to another node. Redis also is fast & scalable engine. So I don't think that any deadlock issues will come. But this technology is still "beta" and no guaranties here.
Posted 07 July 2011 - 07:36 AM
Posted 01 October 2012 - 01:31 AM
I was thinking of nginx to process php and nodejs to send database queries and updates.
I will post my development results and experiences here, when I get them