使用node.js和socket.io向用户显示实时数据
我正在寻求将我们的 Web 应用程序从传统的 PHP/MySQL 优化/升级到更高效的技术。我一直在研究 node.js、socket.io 和 CouchDB,它们看起来很有前途,但我正在寻找建议和一些帮助来选择我们想要的最佳技术。
那么,概述一下当前所做的事情...
我们拥有捕获数据并将其发送到 FTP 服务器(通过 .txt 文件)的设备。 PHP 脚本每 5 分钟运行一次,扫描 FTP 以查找设备发送的 .txt 文件。文件的内容将插入 MySQL 数据库,并删除 .txt 文件。另一个每 15 分钟运行一次的 PHP 脚本将从数据库中整理数据(例如,上一小时的总和值)并生成一个 XML 文档,该文档由 Flash dial 读取。
显然,这里存在很多问题,而且距离实时解决方案还很远,而这正是我们的目标。我们想要的解决方案是,以某种方式,它可以检测 txt 文件何时上传到 FTP,然后仅处理数据(而不是设置运行间隔)。数据仍然需要添加到数据库中,添加到数据库后立即被前端读取。 Flash 将被完全删除,因为它有点……恶心……
有了令人兴奋的新技术,如 Node.js 和 Web Sockets (socket.io),我相信我们可以极大地改进这个过程!我知道 Ajax 能够执行类似的操作,但听说与 Web Sockets 相比,它的开销相当高。我对数据库如何与 Node.js 一起工作也有点模糊,更不用说我们所追求的最佳选择......
谢谢!
I'm looking to optimize/upgrade our web application from the traditional PHP/MySQL, to a more efficient technology. I've been researching node.js, socket.io and CouchDB, which look promising, but am looking for recommendations and some help in choosing the best technologies for what we want.
So, to outline the what is currently done...
We have devices that capture data and sends it to an FTP server (via .txt file). A PHP script runs every 5 minutes, scanning the FTP for .txt files that the devices send. The contents of the files are inserted into a MySQL database, and the .txt file deleted. Another PHP script that runs every 15 minutes will collate data from the database (eg, sum values for last hour) and produce an XML document, which are read by Flash dials.
Obviously, there are plenty of issues here, and it is far from a real-time solution, which is what we are aiming for. The solution we'd like is, that somehow, it could detect when the txt file is uploaded to the FTP, and only process the data then (rather than having a set interval that runs). The data would still need to be added to the database, and be read by the front-end as soon as it is added to the database. Flash would be removed entirely, as its a little...ick...
With exciting new technologies like node.js and Web Sockets (socket.io), i'm sure we could improve this process greatly! I'm aware of Ajax being able to do something like this, but hear it has rather high overheads compared to Web Sockets. I'm also a little hazy with how a database would work with node.js, not to mention the best option for what we're after...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Node 与 NoSQL 配合得很好(尤其是基于 JSON 的 NoSQL),但由于它们是用于处理 Node 中大多数异步数据库并返回 javascript 对象的模块,如果您更喜欢使用 MySQL,我不会放弃使用它。
这是一个与数据库无关的大纲。
Node works well with NoSQL, (especially JSON based NoSQL) but since their are modules for handling most databases in node that are async and return javascript objects I wouldn't dismiss using MySQL if you're more comfortable using it.
here's an database agnostic outline.