PHP:将数据从服务器推送到客户端的最佳方法.....?
问题描述:
在我的项目I need to push some data from server to the client
就像facebook
一样,当some updates are performed in the clients profile
像有人在客户墙上写东西时,Facebook会自动将其推送到客户端。PHP:将数据从服务器推送到客户端的最佳方法.....?
当前I am using AJAX
连续check the DB for the updates
。那是not a good practice
。
我不想依靠客户端进行更新。我希望server should automatically push the data to the client side
在执行与客户端相关的一些更新时。
请推荐一些网址或代码示例这样做......
在此先感谢.....
答
您应该看看APE项目,该项目支持多种与Push相近的变体,例如长轮询,XHRStreaming和WebSockets。
- http://www.ape-project.org/
- http://www.ape-project.org/wiki/index.php/Tutorial:Use_different_transport_method_(JSONP,_XHRStreaming)#Long_Polling
编辑 在短短PHP这样做是不是最好的选择,因为它占用了大量的资源,以保持所有这些连接活着。
答
你需要的是一个彗星/ websocket的方法,我不知道任何PHP彗星实现/框架,但是当你搜索它时,网络上有几个例子。
您正在寻找[推送技术](http://en.wikipedia.org/wiki/Push_technology)。有许多实现,请检查对您有用的东西。 – Khez 2011-04-22 08:34:32