Perform large operations in PHP without running out of memory?
<p>I'm generating about 700 PDFs with dompdf and saving them to the disk. Each one involves a database query to fetch the information for the PDF. When I run it I get about 2 minutes in and then it runs out of memory.</p>

<ol>
<li><p>Why am I running out of memory? Shouldn't each PDF generation consume x memory, then release it when finished?</p></li>
<li><p>What's good practice in PHP for doing large operations like this to avoid strangling your server?</p></li>
</ol>

<p>Some more info: </p>

<ul>
<li>It generates many PDFs before running out of memory (some 100s)</li>
<li>The PDF it fails on is not abnormally large or special in any way. They're all between 4KB and ~500KB</li>
<li>Watching the memory usage as it processes it just slowly climbs in fits and starts until it runs out.</li>
</ul>

<p>I can't get the wysiwyg to code-format properly, so here's a pastie for the snippets in question: <a href="http://pastie.org/3800751" rel="nofollow">http://pastie.org/3800751</a></p>
