PHP:将数据从服务器推送到客户端的最佳方式......?
在我的项目中,当像某人一样在客户端配置文件中执行一些更新时,我需要像 Facebook 那样将一些数据从服务器推送到客户端在客户端的墙上写一些东西,Facebook会自动将其推送到客户端。
目前我正在使用 AJAX
来连续检查数据库的更新
。这不是一个好的做法
。
我不想依赖客户端进行更新。我希望当执行一些与客户端相关的更新时,服务器应该自动将数据推送到客户端。
请建议一些网址或示例代码来这样做......
提前致谢......
In my project I need to push some data from server to the client
like facebook
does, when some updates are performed in the clients profile
like somebody writes something in the wall of the client, Facebook automatically push it to the client side.
Currently I am using AJAX
to continuously check the DB for the updates
. That is not a good practice
.
I don't want to depended on the client side for the updates. I want that the server should automatically push the data to the client side
when some updates are performed related to the client.
Please suggest some url or sample code to do so......
Thanks in advance.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该看一下 APE 项目,它支持多种与 Push 非常接近的变体,例如长轮询、XHRStreaming 和 WebSockets。
编辑
仅使用 PHP 执行此操作并不是最佳选择,因为它需要大量资源来保持所有这些连接处于活动状态。
You should take a look at the APE Project, which supports multiple variations that are as close to Push as you will get, like long-polling, XHRStreaming and WebSockets.
edit
Doing this in just PHP is not the best choice, as it takes up a lot of resources to keep all those connections alive.
你可以使用node.js: http://nodejs.org/
you can use node.js: http://nodejs.org/
你需要的是comet/websocket方法,我不知道任何PHP comet实现/框架,但是当你搜索它时,网上有几个例子。
what you need is a comet/websocket approach, i do not know any PHP comet implementations/frameworks, yet there are several examples on the web when you search for it.