Flushing php output on Safari with php scripts (hosted by Bluehost)

Alec Jacobson

June 13, 2013

weblog/

There are many, many posts about getting php to flush its output while a script is executing. No one solution worked for me, but I finally found a combination of things that did. First of all my default php.ini shows these two relevant lines:
output_buffering = On
zlib.output_compression = Off
Then I put an .htaccess file in the directory that I'd like to have my buffering script with the following line:
SetEnv no-gzip dont-vary
Finally here was my small test php file:
<?php  // not in table tags for IE                         
    @ini_set('zlib.output_compression', 0);
    @ini_set('implicit_flush', 1);
    //for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
    ob_end_flush();
    ob_implicit_flush(1);
?>
<html>
<body>
<?php
echo str_pad('',1024);  // minimum start for Safari
for ($i=10; $i>0; $i--) {
  echo str_pad("$i<br>\n",8);
  // tag after text for Safari & Firefox
  // 8 char minimum for Firefox
  usleep(100000);
}
?>
</body>
</html>