有关将nodejs与php应用程序集成的建议 [英] Recommendation for integrating nodejs with php application

查看:97
本文介绍了有关将nodejs与php应用程序集成的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用PHP编写的现有应用程序(使用Kohana框架),我想进行长时间轮询.从某些方面看,似乎不建议使用PHP进行长时间轮询,而使用诸如nodejs之类的方法则是更好的选择.我的问题是将Node.js(或其他一些很适合长时间轮询的工具)与现有应用程序集成的最佳方法是什么?

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.

推荐答案

可能最好的方法是让node.js侦听端口并将PHP发送消息到该端口.

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

在Node.js中,您可以打开一个套接字进行监听,而在PHP中,您可以使用cURL发送消息.消息可以采用JSON格式.

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.

如果Node.js部件接收到一条消息,则可以将其转发到长轮询浏览器(可能经过一些处理).

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

这篇关于有关将nodejs与php应用程序集成的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆