PHP Flush/ob_flush not working

前端 未结 7 2203
情深已故
情深已故 2020-11-27 07:03

I\'ve tried several attempts at getting my flush and ob_flush to work. I\'ve tried setting the ini to allow buffering, I\'ve tried using several different functions I found

相关标签:
7条回答
  • 2020-11-27 07:33
    <?php
        header('Content-Type: text/html; charset=utf-8');
    
        // I think maybe you can set output_buffering using ini_set here, but I'm not sure.
        // It didn't work for me the first time at least, but now it does sometimes...
        // So I set output_buffering to Off in my php.ini,
        // which normally, on Linux, you can find at the following location: /etc/php5/apache2/php.ini
    
        @ini_set('output_buffering','Off');
        @ini_set('zlib.output_compression',0);
        @ini_set('implicit_flush',1);
        @ob_end_clean();
        set_time_limit(0);
        ob_start();
    
        //echo str_repeat('        ',1024*8); //<-- For some reason it now even works without this, in Firefox at least?
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title>PHP Flushing</title>
        </head>
        <body>
            <h1>Flushing the webpage in real-time using PHP.</h1>
    <?php
        ob_flush();
        flush();
    
        //Note: ob_flush comes first, then you call flush. I did this wrong in one of my own scripts previously.
        for($i=0; $i<5; $i++) {
            echo $i.'<br>';
            ob_flush();
            flush();   
            sleep(1);
        }
    ?>
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题