phpflushphp-7.1

PHP 7.1 flush doesn't work at all


I need to flush content during the script is running. Sounds simple yet there are several discussions about that issue. I've tried everything I was able to find so I thing there has to be something wrong with server. Perhaps some bad conf. I'm able to change server conf if you tell me what to look for.

So far I checked output_buffering (512), output_handler (no value), zlib.output_compression (Off), zlib.output_handler (no value). The server runs plain Apache without fast-cgi or so.

No matter what is the size of flushed string, it does nothing until the script finishes - then everything is rendered together.

I post a sample of my final code but I've tried every code sample I've found online.

// Turn off apache-level compression
@apache_setenv('no-gzip', 1);

// Turn off compression
@ini_set('zlib.output_compression', 0);

session_write_close();

while (ob_get_level()) ob_end_flush();

header( 'Content-type: text/html; charset=utf-8' );
header('Cache-Control: no-cache, must-revalidate');
header("Content-Encoding: identity", true);

for ($i = 0; $i < 10; $i++){

    ob_start(null,4096,PHP_OUTPUT_HANDLER_FLUSHABLE);
    echo "$i";
    echo str_repeat(' ',4096);
    usleep(250000);
    ob_end_flush();
    flush();

}

I began in cakephp 3.5 action but when I wasn't able to get it work I extracted the code to separate .php file and I'm accessing the file directly. Network control suggests that it's not problem of browser caching.

Thank you for every hint.

EDIT: After hours of work I've figured out that it was an antivirus issue. And since almost every antivirus checks webcontent even with SSL these days, I guess there is no guaranteed way to pass partial/chunked content to the user.


Solution

  • To be more clear a enter the result as an answer: After hours of work I've figured out that it was an antivirus issue. And since almost every antivirus checks webcontent even with SSL these days, I guess there is no guaranteed way to pass partial/chunked content to the user.