【问题标题】:iframe comet close on exitiframe 彗星在退出时关闭
【发布时间】:2013-09-30 03:04:40
【问题描述】:

您好,我正在使用标准的 comet co 和 iframe,但离开页面,该方法继续在服务器上运行。我需要检测连接何时关闭。 循环必须是永久性的,而(真的),我不能定期完成。 有人可以帮助我 谢谢

后端;

        set_time_limit(0);
        //Turn of Apache output compression
        // Necessary if you have gzip setup in your httpd.conf (e.g. LoadModule deflate_module modules/mod_deflate.so)
        apache_setenv('no-gzip', 1);
        ini_set('zlib.output_compression', 0);

        //Disable all PHP output buffering
        ini_set('output_buffering', 'Off');
        ini_set('implicit_flush', 1);
        ob_implicit_flush(1);

        for ($i = 0, $level = ob_get_level(); $i < $level; $i++) {
            ob_end_flush();
        } //Flush all levels of the buffer to start

        error_reporting(E_ALL);

        while( true ){
          $a = getAct();
          if($a)
          echo $a;
          $randSleep = mt_rand(400000, 600000);
          usleep($randSleep);
        }

【问题讨论】:

    标签: php apache comet


    【解决方案1】:

    您可以使用 PHP 连接处理功能做到这一点:

    http://php.net/manual/en/features.connection-handling.php

    // Ignore user aborts and allow the script
    // to run forever
    ignore_user_abort(true);
    set_time_limit(0);
    
    echo 'Testing connection handling in PHP';
    
    // Run a pointless loop that sometime 
    // hopefully will make us click away from 
    // page or click the "Stop" button.
    while(1)
    {
        // Did the connection fail?
        if(connection_status() != CONNECTION_NORMAL)
        {
            break;
        }
    
        // Sleep for 10 seconds
        sleep(10);
    }
    
    // If this is reached, then the 'break' 
    // was triggered from inside the while loop
    
    // So here we can log, or perform any other tasks
    // we need without actually being dependent on the 
    // browser.
    

    【讨论】:

      猜你喜欢
      • 2011-01-02
      • 2016-07-05
      • 2013-02-09
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      相关资源
      最近更新 更多