我想用 PHP 实现 Comet 并遇到了这个页面:
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);
}
当客户端离开页面时,如何告诉服务器停止处理循环?否则,我担心循环会在服务器上继续进行,直到某些内容被修改。