問(wèn)題描述
誰(shuí)能給我一個(gè)簡(jiǎn)單的使用 PHP 的彗星技術(shù)示例?
Can anyone give me a good and simple example of the comet technique using PHP?
我只需要一個(gè)使用持久 HTTP 連接或類(lèi)似內(nèi)容的示例.我不想使用輪詢(xún)技術(shù),因?yàn)槲矣蓄?lèi)似的設(shè)置,不僅難以使用和管理它的大量資源.另外我使用的是 IIS7 而不是 Apache.
I just need an example that uses a persistent HTTP connection or something similar. I don't want to use a polling technique, because I have something like that set up and not only is it difficult to work with and manage its a big hog of resources. Also I am using IIS7 not Apache.
一個(gè)很好的例子會(huì)很有幫助,這樣我就可以繼續(xù)使用這種丑陋的投票技術(shù).
A good example would be really helpful so I can move on from this ugly polling technique.
推薦答案
你應(yīng)該使用輪詢(xún),或者使用一個(gè)專(zhuān)門(mén)為長(zhǎng)請(qǐng)求和 COMET 設(shè)計(jì)的 web 服務(wù)器,有一個(gè)好的 JS 后端:
You should use polling, or use a web server which is specially conceived for long requests and COMET, with a good JS backend:
function listen() {
$.get("/mylongrequestfile", {}, function(data) {
$("#mydiv").html(data);
listen(); // then launch again
}));
};
記住COMET是等待數(shù)據(jù),有數(shù)據(jù)返回退出",所以JS后端要解析數(shù)據(jù),重新啟動(dòng)詢(xún)問(wèn)服務(wù)器的過(guò)程.
Remember that COMET is "wait for data, if there's data return and exit", so JS backend will have to parse the data and re-launch the process of asking the server.
在這個(gè)例子中,如果出現(xiàn)服務(wù)器端問(wèn)題或者只是與用戶(hù)端斷開(kāi)連接,整個(gè)過(guò)程都會(huì)被破壞(只有請(qǐng)求成功才會(huì)調(diào)用該函數(shù))
In this example, if there is a server side problem or just a disconnection from the user side, the entire process will be broken (the function is only called if the request is successful)
這篇關(guān)于使用 php 和 jquery 的簡(jiǎn)單彗星示例的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!