Recommendation for integrating nodejs with php application

£可爱£侵袭症+ 提交于 2019-11-27 16:44:48

问题


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.


回答1:


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.




回答2:


I am creating a small hack that would allow you to do this with ease. It is in a very early stage but it has enough code for it to work: https://github.com/josebalius/NodePHP

I plan on updating the readme later today.



来源:https://stackoverflow.com/questions/2808125/recommendation-for-integrating-nodejs-with-php-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!