note 36973 modified in function.flush by danbrown

From: Date: Sat, 14 Feb 2009 06:10:34 +0000
Subject: note 36973 modified in function.flush by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150664@lists.php.net to get a copy of this message
in order to display in HTML pages something like a "progress bar" or if you want to force the web server to flush output to the browser, or the browser to flush as well, you can print a long enough "dummy" string to make the output buffer grow, as you probably know, like: <?php print "["; for($i = 0; $i < 100; $i++){ $spaces.=" "; } // for //and then for($i = 0; $i < 10; $i++){ for($ii = 0; $ii < 200000; $ii++){ //do something slow here } // for print "$spaces|"; flush(); } // for print "]"; /* but this somethin may be not really what you expect in a progress bar, as it prints spaces (although rendered as single by the browser) between the bar units.. you can solve this using $spaces.="<!-- bufferme -->"; /* print "["; for($i = 0; $i < 100; $i++){ $spaces.="<!-- bufferme -->"; } // for //and then for($i = 0; $i < 10; $i++){ for($ii = 0; $ii < 200000; $ii++){ //do something slow here } // for print "$spaces|"; flush(); } // for print "]"; //which looks nice as a progress bar.. ?> --was-- in order to display in HTML pages something like a "progress bar" or if you want to force the web server to flush output to the browser, or the browser to flush as well, you can print a long enough "dummy" string to make the output buffer grow, as you probably know, like: print "["; for($i = 0; $i < 100; $i++){ $spaces.=" "; } // for //and then for($i = 0; $i < 10; $i++){ for($ii = 0; $ii < 200000; $ii++){ //do something slow here } // for print "$spaces|"; flush(); } // for print "]"; /* but this somethin may be not really what you expect in a progress bar, as it prints spaces (although rendered as single by the browser) between the bar units.. you can solve this using $spaces.="<!-- bufferme -->"; /* print "["; for($i = 0; $i < 100; $i++){ $spaces.="<!-- bufferme -->"; } // for //and then for($i = 0; $i < 10; $i++){ for($ii = 0; $ii < 200000; $ii++){ //do something slow here } // for print "$spaces|"; flush(); } // for print "]"; //which looks nice as a progress bar.. http://php.net/manual/en/function.flush.php

« previous php.notes (#150664) next »