Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendation for integrating nodejs with php application

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.

like image 738
jhchen Avatar asked May 11 '10 04:05

jhchen


People also ask

Can we integrate node js with PHP?

The easiest way to achieve this is to run both Node. js and PHP on the same server, but on different ports. A node. js server can then just do a local HTTP request to the PHP server and do something with the response.

Which is the best for next project PHP vs Nodejs?

Winner: Node. js wins the Node. js vs PHP performance battle as it offers better speed and a seamless and concurrent experience both for the developer and end-user.

When should we use node js over PHP?

High Speed and Consistent Callback from Servers- Web applications developed using Node. js tend to perform better while consistently sending requests to the server. Its asynchronous architecture allows non-blocking execution which is great for any project that needs speed.

Is PHP more secure than Nodejs?

Node. js is fast and lightweight. It is more secure than PHP.


1 Answers

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.

like image 121
edwin Avatar answered Oct 08 '22 22:10

edwin