title: PHP can't use 300MB of RAM
body: <p>I'm trying to increase the allowed memory for certain PHP script. No matter what I do, for instance this:</p>
  
  <pre><code>ini_set('memory_limit', '512M');
  </code></pre>
  
  <p>... the script always runs out of memory at around 300MB:</p>
  
  <pre><code>Fatal error: Out of memory (allocated 25165824) (tried to allocate 343810589 bytes) in \\Foo\phpQuery\phpQuery.php on line 255
  </code></pre>
  
  <p>I've verified by several means that <code>memory_limit</code> is actually changed. The issue seems to be that PHP can't physically allocate a total of 300&nbsp;MB of memory (25165824&nbsp;bytes + 343810589&nbsp;bytes = 352&nbsp;MB).</p>
  
  <p>I've tried both PHP/5.3.0 and PHP/5.3.9 in two different Windows-based computers with the following specs:</p>
  
  <ul>
  <li>Windows XP / Windows Server 2003 (both computers are 32-bit boxes with 1GB or RAM)</li>
  <li>Official PHP 32-bit VC9 binaries</li>
  <li>Running as Apache 2.2 module (third-party 32-bit VC9 binaries)</li>
  </ul>
  
  <p>I understand that using half of the physical RAM will force swapping and slow things down as hell but I just need to make sure the script actually works so it can be deployed to the live server. I've also tried larger values (which procuded the same error) and smaller values (with either made my script hit the limit or made Apache crash).</p>
  
  <p>What can be the source of this apparently hard-coded memory limit?</p>
  
  <p><strong>Update #1:</strong> I've done further testing with the Windows Server 2003 box (which is actually a VMWare virtual machine). I've increased the "physical" RAM to 2&nbsp;GB and I've verified that the paging file is allowed to grow up to 1152&nbsp;MB. Task manager shows that current transaction load is 886&nbsp;MB and there're 1,5&nbsp;GB of free physical memory. However, I'm getting the same error with <em>exactly the same figures</em>.</p>
  
  <p><strong>Update #2:</strong> As I said, the <code>memory_limit</code> directive is fine. It shows up in both <code>ini_get()</code> and <code>phpinfo()</code>. The error message you'd get is slightly different from mine; mine indicates a PHP <em>crash</em>. Please compare:</p>
  
  <pre><code>Out of memory (allocated 25165824) (tried to allocate 343810589 bytes)
  Allowed memory size of 25165824 bytes exhausted (tried to allocate 343810589 bytes)
  </code></pre>
  
  <p>I'll try to compose a script to reproduce the issue and report back.</p>