title: ob_start() output buffering doesn't work with ob_gzhandler compression
body: <p>I'm confused about using ob_start and ob_start("ob_gzhandler") functions.
  I have a test php script in which I'm trying to implement a simple caching system. Here is the script:</p>
  
  <pre><code>&lt;?php
  
  ob_start();
  
  function writeCache($content, $filename) {
    $fp = fopen($filename, 'w');
    fwrite($fp, $content);
    fclose($fp);
  }   
  
  function readCache($filename, $expiry) {
  if (file_exists($filename)) {
    if ((time() - $expiry) &gt; filemtime($filename))
      return FALSE;
    $cache = file($filename);
    return implode('', $cache);
  }
  return FALSE;
  } 
  
  $headfile='cache/head.cache';
  $headtime=86400; //1 day cache
  //  check if a valid head cache exists
  if (!$head = readCache($headfile,$headtime)) {
  
  $title='testing output buffering in caching';
  $description='this page is using ob_start for caching';
  $keywords='ob_start,output,buffering';
  
  echo '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;';
  echo '&lt;meta name="description" content="'.$description.'" /&gt;';
  echo '&lt;meta name="keywords" content="'.$keywords.'" /&gt;';
  echo '&lt;meta name="title" content="'.$title.'" /&gt;';
  echo '&lt;link rel="icon" href="'.filemtime("favicon.ico").'/favicon.ico" type="image/x-icon" /&gt;';
  echo '&lt;link rel="shortcut icon" href="'.filemtime("favicon.ico").'/favicon.ico" type="image/x-icon"/&gt;';
  echo '&lt;title&gt;'.$title.' &lt;/title&gt;';
  echo '&lt;link rel="stylesheet" type="text/css" href="/css/'.filemtime("css/style.php").'/style.php" media="screen" /&gt;';
  echo '&lt;/head&gt;';
  echo 'head cached at '.date('Y-m-d H:i:s');
  $head = ob_get_contents();
  ob_clean();
  writeCache($head,$headfile);
  
  } 
  
  //body cache
  $bodyfile='cache/body.cache';
  $bodytime=86400; //1 day cache
  
  //  check if a valid body cache exists
  if (!$body = readCache($bodyfile,$bodytime)) {
  
      echo '&lt;body&gt;';
      echo '&lt;p&gt;this is the body of html doc!&lt;/p&gt;';
      echo '&lt;p&gt;this part of page was cached in buffer&lt;/p&gt;';
      echo 'body cached at '.date('Y-m-d H:i:s');
      $body = ob_get_contents();
     ob_clean();
     writeCache($body,$bodyfile);
  }   
  
  //footer cache
  $footerfile='cache/footer.cache';
  $footertime=86400; //1 day cache
  
  //  check if a valid footer cache exists
  if (!$footer = readCache($footerfile,$footertime)) {
  
      echo '&lt;p&gt;this is a footer section!&lt;/p&gt;';
      echo '&lt;/body&gt;&lt;/html&gt;';
      echo 'footer cached at '.date('Y-m-d H:i:s');   
      $footer = ob_get_contents();
      ob_clean();
      writeCache($footer,$footerfile);
  }   
  ob_end_clean(); 
  echo $head.$body.$footer; 
  echo '&lt;p&gt;usual output of data...'.date('Y-m-d H:i:s');
  ?&gt;
  </code></pre>
  
  <p>Script outputs these lines:</p>
  
  <pre><code>head cached at 2012-03-29 19:34:36
  
  this is the body of html doc!
  
  this part of page was cached in buffer
  body cached at 2012-03-29 19:34:36
  
  this is a footer section!
  footer cached at 2012-03-29 19:34:36
  
  usual output of data...2012-03-29 20:13:59
  </code></pre>
  
  <p>All three cache files are present in cache directory and everything seem to work ok. But before I implemented output buffering into the script I had </p>
  
  <pre><code>ob_start("ob_gzhandler",9);
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>ob_start();
  </code></pre>
  
  <p>at the beginning of script.</p>
  
  <p>So i used gzip compression on my test page. Now if I try to change ob_start()
   to ob_start("ob_gzhandler",9) I got content type error in my browser and blanc window. Why can't I use not only output buffering, but gzip compression on my page too? Is there a way to organize output buffering caching like this using gzip compression of content too?</p>
  
  <p>Hope someone knows the answer! Thanks!</p>