The thing i am trying to achieve is a hybrid server to run and handle the needs of my Social Network website.
I have created all of it on PHP and database is MySql, for real time updates i have used AJAX long polling which checks for new messages in every 'x' seconds. But i don't want time gap between rechecks and that's why i decided to use short polling. Short polling is achieved through Node.js+Socket.io.
After the "NodeApp" is built, i am going to combine it on my website which is using apache. How can i integrate both of them together? For example : Pages are :
How can i load my php page as is and messages in between which is written in node.js for real time updates just like FB.(using websockets and then fall back to whatever is supported, this is done using [socket.io]) A small overview : http://postimg.org/image/p3vq4tkvr/
Doing right now is about the same. I'll share my experience with you. It may come in handy. We was ready social network engine to phpFox. Decided to "spice up" section of personal messages using Node.js (used as a transport socket.io).
From the beginning, there was a problem with the connection PHP (phpFox) with Node.js. The bridge was found - dNode. This module allows you to use TCP-protocol to send data between virtual servers (drivers dNode there for many popular programming languages.)
Next problem - the database. Initially, we used MySQL with a list of tables (for mail):
mail | mail_text | user | user_info
Some tests have shown that use MySQL with node.js is not rational. For this reason it was decided to use for the "Dialogues" (the code name for personal messages written on node.js) non-relational database MongoDB. The script was written by Python (can be used and PHP, but for such tasks, I prefer to use Python - the best performance and speed of execution of scripts) that "peregenal" MySQL database to MongoDB, created such a scheme:
messages | dialogs | texts
The collection of unique dialogs are stored messages:
dialog_id | owner_user_id | viewer_user_id | last_message | some_info
And then everything is clear:
http://site.com/mail/ dNode, PHP passes the user_id on the side node.js.user_id - he pulls out all the "dialogue" with the collection of "dialogs" and draws the main page.http://site.com/mail/{John user_id}.That's it. I hope my experience will help you with something :)
Good luck!