title: how to redirect STDOUT to a file in PHP?
body: <p>The code below almost works, but it's not what I really meant:</p>
  
  <pre><code>ob_start();
  echo 'xxx';
  $contents = ob_get_contents();
  ob_end_clean();
  file_put_contents($file,$contents);
  </code></pre>
  
  <p>Is there a more natural way?</p>