1
votes

We are making a small real-time collaborative web-application, so far written in js/php running on apache. For the collaboration and chat part we'll need sockets so we thought about using nodeJS with socket.io.

These two answers show how to put php/apache and nodeJS together. My question would be:

  1. How could messages be send back-and-forth between the two servers? (Three i guess since the chat part would need a server of its own.) cURL for php->nodeJS; ajax for nodeJS->php?
  2. How can the nodeJS server serve multiple instances of the collaboration (for different currently running collab-projects)/chat (for different groups of people communicating with eachoter in "other chat rooms") program. socket.io has a chat program example but its a single page single application.

I don't need complex step-by-step answers, but I have no idea how more complex than barebone nodeJS apps work, and at the moment I am at a complete loss.

1
A node.js server process just represents another server process that is up and running and listening for some sort of incoming connections. From outside the node.js app, it appears no different than a server written in C++ or smallTalk or any other language. It can communicate with any other server process just the same way as anything else. It can make http requests to another server or it can listen for http requests from another server or the two can connect more continuously using some other socket-based connection such as webSocket.jfriend00
FYI, the whole architecture might be simpler if you just wrote the whole thing in node.js or the whole thing in PHP. Then you wouldn't have to deploy multiple servers or have them communicate. You can do webSocket/socket.io connections in PHP if you want and you can likely do anything your current PHP code is doing in node.js too. So, maybe it makes sense to just pick one server environment and implement it all in that one environment (that's what I would do).jfriend00

1 Answers

1
votes
  1. From my experience using a 'message-broker' like redis(the pub/sub part of redis) works really well to allow servers to 'communicate' to each other. You can check out http://redis.js.org/#api-publish-subscribe
  2. Socket.io does support having different groups/chats/projects by using the builtin rooms, check here: http://socket.io/docs/rooms-and-namespaces/#rooms I recommend using consistent naming for the rooms like group-${group.id} or g-${group.id} for short.

Extra note: socket.io has support to use redis as a mean to scale beyond 1 nodejs instance, see the socket.io-redis npm package.