title: Problems with ob_file_callback and fwrite
body: <pre><code>&lt;?php
  
  $forks = 2;
  
  switch ($forks) {
      case 1:
          $ob_file = fopen('case1.txt','w');
          function ob_file_callback($buffer)
  {
          global $ob_file;
          fwrite($ob_file,$buffer);
  }
          ob_start('ob_file_callback');
          echo $ip = $_SERVER['REMOTE_ADDR'];
          ob_end_flush();
  
          header("LOCATION: case1.php");
  
      case 2:
      $ob_file = fopen('case2.txt','w');
  function ob_file_callback($buffer)
  {
    global $ob_file;
    fwrite($ob_file,$buffer);
  }
  ob_start('ob_file_callback');
  echo $ip = $_SERVER['REMOTE_ADDR'];
  ob_end_flush();
      ;
       header("LOCATION: case2.php");
          }
  
  
  ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  </code></pre>
  
  <p>If I choose $forks = 1, it write to case2.txt which is nuts but it does. Not only does it fail to redirect LOCATION, but it won't even show the default page. It claims there's an issue on the header location because headers have already been sent, which is surreal. Then, even though I'm not asking it to redeclare ob_file_callback because it's in case 2 and I've opted for case 1, it claims cannot redeclare ob_file_callback on the ob_file_callback that's sitting inside case 2.</p>
  
  <p>If I choose $forks = 2, it doesn't write into any file whatsoever and just claims it can't modify header information so it's another header relocation fail, which is also stupid. It does however give me the default page, but that just confuses me further.</p>
  
  <p>My problem with fwrite, ob_start or ob_end_flush or whatever's doing the writing to file, is that it'll only write it once. Either that or it's erasing the file everytime it opens it, so the resulting issue is that when forks 1 does indeed write to case2.txt, it's always only ever 1 string sitting there.</p>
  
  <hr>
  
  <p>First round of corrections: </p>
  
  <pre><code>    &lt;?php
  
       function ob_file_callback($buffer)
  {
       global $ob_file;
       fwrite($ob_file,$buffer);
  }
  $forks = 1;
  switch ($forks) {
      case 1:
       $ob_file = fopen('case1.txt','w');
  
       ob_start('ob_file_callback');
       echo $ip = $_SERVER['REMOTE_ADDR'];
       ob_end_flush();
       header("LOCATION: case1.php");
       exit;
  break;
  
     case 2:
      $ob_file = fopen('case2.txt','w');
      ob_start('ob_file_callback');
      echo $ip = $_SERVER['REMOTE_ADDR'];
      ob_end_flush();
      header("LOCATION: case2.php");
          }
      exit
  ?&gt;
  </code></pre>