問(wèn)題描述
在我的項(xiàng)目中 我需要像
,當(dāng) facebook
那樣將一些數(shù)據(jù)從服務(wù)器推送到客戶端在客戶端配置文件中執(zhí)行一些更新時(shí)
就像有人在客戶端的墻上寫(xiě)東西一樣,F(xiàn)acebook 會(huì)自動(dòng)將其推送到客戶端.
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
不斷檢查數(shù)據(jù)庫(kù)的更新
.那是不是一個(gè)好習(xí)慣
.
我不想依賴客戶端進(jìn)行更新.我希望 服務(wù)器應(yīng)該在執(zhí)行與客戶端相關(guān)的某些更新時(shí)自動(dòng)將數(shù)據(jù)推送到客戶端
.
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.
請(qǐng)建議一些網(wǎng)址或示例代碼來(lái)這樣做......
Please suggest some url or sample code to do so......
提前致謝.....
推薦答案
你應(yīng)該看看 APE 項(xiàng)目,它支持多種與 Push 盡可能接近的變體,比如長(zhǎng)輪詢、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 中執(zhí)行此操作并不是最佳選擇,因?yàn)樗鼤?huì)占用大量資源來(lái)保持所有這些連接的活動(dòng)狀態(tài).
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.
這篇關(guān)于PHP:將數(shù)據(jù)從服務(wù)器推送到客戶端的最佳方式......?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!