2009-12-25 62 views
1

我想在PHP中實現彗星和整個這個頁面來了:如何阻止此AJAX?

http://www.zeitoun.net/articles/comet_and_php/start

第二種方法在文章中解釋了我的正常工作。在後端PHP文件,循環似乎是無限的:

// infinite loop until the data file is not modified 
    $lastmodif = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0; 
    $currentmodif = filemtime($filename); 
    while ($currentmodif <= $lastmodif) // check if the data file has been modified 
    { 
    usleep(10000); // sleep 10ms to unload the CPU 
    clearstatcache(); 
    $currentmodif = filemtime($filename); 
    } 

當客戶離開頁面,如何告訴服務器停止處理循環?否則,我擔心循環會在服務器上繼續運行,直到某些內容被修改。

回答

1

您需要檢查connection_status函數。

+0

PHP文檔說:「然而,當遠程客戶端斷開連接時,腳本會被終止,這是默認行爲。」這是否意味着當啓動AJAX請求的客戶端斷開連接時,循環會中斷? – Nirmal 2009-12-25 04:49:50

+0

要做的最好的事情就是測試它並找出答案。 – JAL 2009-12-25 05:43:15

+0

謝謝。我會玩這個,並找出答案。修復完成後會更新。 – Nirmal 2009-12-25 10:06:11