Finally, my working solution is No. 1.
When a user establishes a connection with node.js / socket.io, he simply sends a “subscribe” message to node.js with his PHP session identifier. node.js checks authorization using a POST request on a PHP server, and if everything is ok, the user can establish a connection.
Frontend sends all requests to PHP, as it was before node.js. PHP modifies some object, checks who can access the modified object, and sends a message (via AMQP or redis pub / sub, etc.) to node.js:
{ id_object: 125342, users: [5, 23, 9882] }
node.js then check which of the listed users has active sockets and for each user sends a GET request to PHP:
{ userId: 5, id_object: 125342 }
A special PHP controller that receives this request starts a request to get an object with the rights of this user ID and then sends a message to node.js with the resulting response. node.js, then through socket sends a response to the external user interface.
source share