如何停止这个AJAX?
我想用 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);
}
当客户端离开页面时,如何告诉服务器停止处理循环?否则我担心循环会在服务器上一直持续下去,直到某些内容被修改为止。
I wanted to implement Comet in PHP and came across this page:
http://www.zeitoun.net/articles/comet_and_php/start
The second method explained in the article works fine for me. In the backend php file, the loop seems to be infinite:
// 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);
}
When the client leaves the page, how to tell the server to stop processing the loop? Otherwise I fear that the loop is going to go on and on on the server until something is modified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查
connection_status
函数。You need to check the
connection_status
function.