0
votes

There are two socket servers that have to send messages to each other. The first one is a node.js server with socket.io. The second is ja php websocket (ratchet - http://socketo.me/). The second server (ratchet) runs in a php application (created with a php framework like laravel or symfony) that contains a basic chat application.

The node.js server is like a global manager that can convey messages to multiple socket servers.

The communication ways are planned as follows:

Scenario a)
-> client / browser sends a message via websocket
-> php app receives message from browser by ratchet socket and stores this message in database
-> php sends / forwards message to node.js via socket
-> php sends response to client / browser via websocket

Scenario b)
-> node.js server sends a message to all connected php clients via socket
-> php receives message from node.js and stores this message in database
-> php sends this message to one or more connected browser clients
-> browser receives messages from php via websocket

What is the best way to enable this communication way? The browser is already able to talk to the ratchet server. But I have no idea how the ratchet server can talk to the node.js server an act as a normal socket client so that they will establish and hold a connection to each other. Is there a command to send a “hello, I am a new client that wants to establish a connection” message to the node.js server or vice versa?

Is this a good concept at all? Or is there a better way to send socket messages over multiple instances? Are there any tips, tutorials or examples? Other questions to this topic are very old or contains a different setup.

1
I'd probably use this : github.com/ratchetphp/Pawl - Loïc

1 Answers

3
votes

I'd probably use this : https://github.com/ratchetphp/Pawl to have PHP sending messages to nodejs.

Then about the concept being good, I think not.

There is no point in having two differents websockets servers imo.

I'd probably use only one websockets server (nodeJS), and have PHP and node "talk" together through a messaging queue like rabbitMQ / REDIS

quick drawing