是否可能将Nodejs与Cakephp集成? [英] Is possible integrate Nodejs with Cakephp?

查看:210
本文介绍了是否可能将Nodejs与Cakephp集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实时监控用户在注释表中输入的数据。
我有一个Apache服务器运行,并假设在端口1337上有一个节点服务器。

I want to monitor in real time the data that users enter in comments table. I have an Apache server running, and suppose that has a node server on port 1337.

我每次有人保存新的数据,例如返回注释中的表行总数,并显示在视图

How would I do that every time someone save new data, eg return me the total number of table rows in comment and show it in a view?

也许方法是使 $ this-> Comment-> save($ this-> request-> data); 使用 Httpsockect 使用其他端口?

Maybe way is to make the $this->Comment->save($this->request->data); using a different port using Httpsockect?

推荐答案

是的,可以。

解决这个问题,让我给你我的想法

You have multiple ways of solving this, let me give you my ideas

你可以简单地使用长轮询,不使用Node.js。

You can simply use long-polling and don't use Node.js at all. It's a suitable solution if there won't be too much traffic there, otherwise you will have a bad time.

您可以使用websockets,不要使用Node.js。这是一个合适的解决方案,如果不会有太多的流量存在,否则你会有一个不好的时间。在所有。 您可以在这里找到有关websockets和PHP的基本指南。虽然,我几乎可以肯定你将无法创建房间,也就是发送特定评论的通知。

You can use websockets and don't use Node.js at all. Here you have a basic guide about websockets and PHP. Although, I am almost sure you won't be able to create "rooms", that is, sending notifications for specific comments.

您也可以使用棘手。这是一个更复杂的库来处理websockets,它支持房间。

You can also use Ratchet. This is a more sophisticated library to handle websockets and it supports rooms.

最后,如果你想完全潜入Node.js和CakePHP,我建议开始观看此次关于Cakefest 2012的演讲,其中详细描述了您的情况。

Lastly, if you want to full dive in with Node.js and CakePHP, I would suggest start by watching this talk given on Cakefest 2012 which exactly describe your scenario.

观看完毕后,您可能想了解一下 Socket.io 。这是一个更复杂的解决方案,但它是我在集成CakePHP和Node.js以创建实时应用程序时使用的。

After you have watched that, you might want to learn a little about Socket.io. This is a more complex solution, but it's what I have used when integrating CakePHP and Node.js to create real time applications.

这里的策略是让用户加入会议室访问/ article / view / 123时,假设房间名称为articleID,那么socket.io将监听此房间中发生的事件。

The strategy here is to have the users join a room when they visit /article/view/123, let's say the room name is the articleID, then socket.io will be listening for events happening in this room.

你将有一个Cakephp方法来处理保存。然后,当用户提交表单时,你不直接调用Cake操作,你有socket.io来分派一个事件,然后在你的事件中你传递数据到服务器(Node.js),nodejs会调用你的cakephp函数保存数据。当Nodejs从CakePHP收到确认,然后你广播一个事件(使用socket.io),这个事件会让连接到该房间的所有用户发表评论。

You will have a Cakephp method that handles the save. Then, when user submits the form you don't call directly the Cake action, you have socket.io to dispatch an event, then in your event you pass the data to the server (Node.js) and nodejs will call your cakephp function that saves the data. When Nodejs receives confirmation from CakePHP then you broadcast an event (using socket.io), this event will let know all users connected to that room that a comment has been made.

这篇关于是否可能将Nodejs与Cakephp集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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