I have an existing PHP application, to which I need to add realtime notifications. In order to achieve this I have installed node.js (intending to add socket.io for all real time functionality)
However. Despite spending the last three hours researching and trying to get my head around how to integrate the two, I have found myself no closer to gaining an understanding.
I am currently using the following:
- Apache
- PHP
- Nginx (as a reverse proxy to Apache for all static content like images/css files etc)
- MySQL
I have code already written which sends an event from the client to PHP and inserts a notification into the database. When the recipient refreshes their page they of course see the notification. I simply need node.js to handle the real time pushing to the client but am at a loss as to how to go about setting it up.
What I really need to know, given this scenario, is the following:
- How/when is the node.js/websocket connection to the client instantiated, given that I wish all content to still be served via Apache/PHP?
- How can I send a message from PHP to Node.js and instruct it to push the notification to the client?
- What kind of back end modifications do I need to make to my setup in order to support this?
Ultimately I would like to simply be able to run a PHP function and expect node.js/socket.io/websockets to push the notification to the client. I just have no idea how to get there.
Thanks in advance for any examples/information/guides.