title: How to stop a PHP output buffer from going over the memory limit?
body: <p>Most of my PHP apps have an ob_start at the beginning, runs through all the code, and then outputs the content, sometimes with some modifications, after everything is done.</p>
  
  <pre><code>ob_start()
  //Business Logic, etc
  header-&gt;output();
  echo apply_post_filter(ob_get_clean());
  footer-&gt;output();
  </code></pre>
  
  <p>This ensures that PHP errors get displayed within the content part of the website, and that errors don't interfere with <code>header</code> and <code>session_*</code> calls.</p>
  
  <p>My only problem is that with some large pages PHP runs out of memory. How do I stop this from happening?</p>
  
  <p>Some ideas:</p>
  
  <ol>
  <li>Write all of the buffered content to a temporary file and output that.</li>
  <li>When the buffers reaches a certain size, output it. Although this might interfere with the post filter.</li>
  <li>Raise the memory limit (thanx @troelskn).</li>
  </ol>
  
  <p>Whats the drawbacks on each of these approaches? Especially raising the memory limit?</p>