Node.js and PHP on the same server

3

I have a dedicated CentOS 6.5 server with Plesk Panel 12 installed, with several sites in php. I would like to develop a chat with node.js and integrate it with some sites made in php. Only this chat needs to retrieve some information from the user that is logged in Ex: The user can only access the chat if it is logged in. What would be the best way to integrate the two things PHP + Node.js?

Solution:

I followed Lauro Moraes' suggestion on this question: Integrating nodejs application with php site into distinct servers ?, and I did what Guilherme suggested. The client logs in to the PHP site, the session data is saved in the database in case I used Redis. In the php part I request Node.js via socket.io by sending the cookie with the session id. In Node.js I get this session id, I consult the Redis database and I release access.

    
asked by anonymous 27.11.2014 / 04:32

1 answer

3

Apparently you are wanting to build an architecture with SSO (Single sign-on). SSO is defined as a single entry point, ie you need to authenticate once. This allows automatic access to various modules of a system, without the need to enter your login and password in each module.

To implement SSO, you must build an architecture to perform this communication between different systems. In your case, there is a relatively simple approach to your question: saving the information in session state with PHP in a database, and reading, with Node.js, the session cookie and checking it in the database to make sure the user is logged in.

There are other similar solutions like the use of memcache in Node.js , but all have a relatively large implementation, which would not be recommended to put here (would take up too much screen space).

References

What is Single Sign-On < br> Sharing data between php and node.js via cookie securely

    
27.11.2014 / 08:05