My code:
@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
@ob_end_clean();
set_time_limit(0);
function show_status($done, $total, $size=30) {
static $start_time;
if($done > $total) return;
if(empty($start_time)) $start_time=time();
$now = time();
$perc=(double)($done/$total);
$bar=floor($perc*$size);
$status_bar="[";
$status_bar.=str_repeat("=", $bar);
if($bar<$size){
$status_bar.=">";
$status_bar.=str_repeat(" ", $size-$bar);
} else {
$status_bar.="=";
}
$disp=number_format($perc*100, 0);
$status_bar.="] $disp% $done/$total";
@$rate = ($now-$start_time)/$done;
$left = $total - $done;
$eta = round($rate * $left, 2);
$elapsed = $now - $start_time;
$status_bar.= " remaining: ".number_format($eta)." sec. elapsed: ".number_format($elapsed)." sec.";
echo "$status_bar\r";
flush();
if($done == $total) {
echo "\n";
}
}
The call is simply show_status($count, $total_count); - its not working on my server for some reason, but I know the code above works (came from the net, and Ive used it before on another server). Problem Im having now on my current server is that its not outputting it per execution, only seeing the end result (100%) once its processed everything.
- Output buffering is set to Off (even though this shouldnt be needed because its being executed via CLI)
- zlib.output_compression set to Off
- see first 4 lines of code to other settings im trying to explicitly set as well
- Also have "SetEnv no-gzip dont-vary" in a .htaccess as this is apparently another cause of flush() not working
What am I missing!? This isnt a browser issue because once again, Im running this via the CLI! PS: Im running this on WAMP with php 5.3.6 with apache 2.2.16