Search code examples
phpflush

Progress bar not working flush


I got big problem, becouse i tested everything to make it works, but`s not - yet :)

i got simple for loop and there is a star, end, flush inside, but still my browser load all output at the and of loop, and i took for this question simple example:

<?php

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

    echo "<br> Line to show.";
    echo str_pad('',4096)."\n";    

    ob_flush();
    flush();
    sleep(2);
}

echo "Done.";

ob_end_flush();
?>                              

a i`vd setup all about outpuuting_bufforing, zlib, gzib, and other alls. Exacly in htacces, script, file, even in php.ini, apache. I got dedicaded server so can configure what i need. Can some1 tell me what more can i try? Ofc there is no error in any log file.

Thanks for advice !


Solution

  • The comments in the official PHP documentation for ob_flush() mention, that most browsers have an all-or-nothing approach to loading content. Therefore the browser will not show anything until the whole page is loaded.

    See http://php.net/manual/de/function.ob-flush.php#109699

    This means that flushing output to the browser will not work for you.

    The alternative would be to start the initial request via AJAX and then use a second request to provide information about the current progess.