0

こんにちは、iframe で標準の comet co を使用していますが、ページを離れてもメソッドはサーバー上で実行され続けます。接続がいつ閉じられたかを検出する必要があります。サイクルは永続的でなければなりませんが (true)、定期的に終了することはできません。誰かが私を助けることができます、ありがとう

バックエンド;

        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);
        }
4

1 に答える 1

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.
于 2013-09-30T03:07:03.743 に答える