如何停止这个AJAX?

发布于 2024-08-16 05:23:31 字数 697 浏览 2 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-08-23 05:23:32

您需要检查 connection_status 函数。

You need to check the connection_status function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文