問題描述
在我的項目中 我需要像
,當 facebook
那樣將一些數據從服務器推送到客戶端在客戶端配置文件中執行一些更新時
就像有人在客戶端的墻上寫東西一樣,Facebook 會自動將其推送到客戶端.
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.
目前我正在使用 AJAX
不斷檢查數據庫的更新
.那是不是一個好習慣
.
我不想依賴客戶端進行更新.我希望 服務器應該在執行與客戶端相關的某些更新時自動將數據推送到客戶端
.
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......
提前致謝.....
推薦答案
你應該看看 APE 項目,它支持多種與 Push 盡可能接近的變體,比如長輪詢、XHRStreaming 和 WebSockets.
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.
- http://www.ape-project.org/
- http://www.ape-project.org/wiki/index.php/Tutorial:Use_different_transport_method_(JSONP,_XHRStreaming)#Long_Polling
編輯僅在 PHP 中執行此操作并不是最佳選擇,因為它會占用大量資源來保持所有這些連接的活動狀態.
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.
這篇關于PHP:將數據從服務器推送到客戶端的最佳方式......?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!