I’ve been trying for days to make a progress bar using just PHP. I’ve learned that having gzip enabled disrupts the functions of ob_flush() and flush(), so I had Dreamhost disable gzip for the domain I needed it on. Still didn’t work. I’ve tried many MANY different scripts, here’s the most basic:
<?php
ob_start();
for($i=0; $i<5; $i++) {
echo $i."
";
ob_flush();
flush();
sleep(1);
}
ob_end_flush();
}
?>
This should print the number of the current iteration of the for loop, once a second, for 5 seconds. What it does instead is load the page for 5 seconds, then print all the numbers at once.
I looked into my php.ini and saw that the output_buffering value was set to 4096, which I thought to mean that I had to have at least 4096 bytes in the buffer before it’d print to the page. I tried constructing a variable that was 4096 bytes long, appending it to the output buffer as a javascript tag so it wouldn’t actually show up on the page (but it was in the source), then doing ob_flush() and flush()…STILL didn’t work.
I’m totally baffled here. I really need to know what I can do. Printing my $_SERVER array reports:
[HTTP_ACCEPT_ENCODING] => gzip, deflate
And so does my other subdomains and my main domain, so I think I missed something.
I’d like to avoid setting up my own php.ini, but if it’s unavoidable I will do it.