views:

407

answers:

2

I have an existing app written in PHP (using Kohana framework) and I want to do long polling. From some things I read it seems that doing long polling with PHP is not advisable and using something like nodejs is a better choice. My question is what's the best way to integrate nodejs (or some other well suited tool for long polling) with an existing application?

For clarification my app basically is a browser plugin that you can use to send data to groups of other people. When that data is sent, I want the recipients, if they are online and also have the browser plugin, to instantly receive that data and be notified.

+2  A: 

Possibly the best way is to let node.js listen to a port and to let PHP send messages to that port.

In Node.js you can just open a socket for listening and in PHP you can use cURL to send messages. The messages can be in JSON-format.

If the Node.js-part receives a message, it can forward it, possibly after some processing, directly to the long-polling browser.

edwin
A: 

@edwin please you post some example code how it can be done, i also i am using kohana php and i wish to add real time status update notification to my apps but i am new to node.js. i will be grateful for your help