Random "PHP Fatal error: Out of memory" errors
<p>Since I moved a PHP app to a new server (PHP/5.3.8 running as Apache 2.2 module on 32-bit Windows Server 2003 R2) I'm getting random errors in the PHP error log:</p>

<pre><code>[09-Jan-2012 19:45:12] PHP Fatal error:  Out of memory (allocated 786432) (tried to allocate 17 bytes) in D:\site\util\odbc-connection.php on line 675
[10-Jan-2012 17:56:49] PHP Fatal error:  Out of memory (allocated 1310720) (tried to allocate 6144 bytes) in D:\site\logic\data.php on line 630
[10-Jan-2012 17:58:52] PHP Fatal error:  Out of memory (allocated 524288) (tried to allocate 393216 bytes) in D:\site\users\edit-user.php on line 458
</code></pre>

<p>I'm confused for the following reasons:</p>

<ol>
<li><p>It is <strong>not</strong> the standard error message you get when <code>memory_limit</code> is reached:</p>

<pre><code>Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 800001 bytes)
</code></pre></li>
<li><p>Whatever, <code>memory_limit</code> defaults to <code>256MB</code> on the server and is set to <code>128MB</code> on this app (thus 524,288 bytes should not be a problem).</p></li>
<li><p>In the reported lines there's normally pretty innocent code, such as the start of function definitions...</p>

<pre><code>function linea($html){
</code></pre>

<p>... or foreach() loops of very small arrays:</p>

<pre><code>foreach($perfiles_basicos as $c =&gt; $v){
</code></pre></li>
</ol>

<p>I think I've already discarded all the obvious stuff (I've even searched for the  <code>memory_limit</code> string in all *.php, *.ini, .htaccess and *.conf files in the hard disk) and I've written code to detect and log changes to the "128MB" limit (nothing was ever found) so I'm pretty clueless right now.</p>

<p>Any hint or idea?</p>

<hr>

<p><strong>Update #1:</strong> Apache's <code>error.log</code> shows that the web server gets restarted after I get an <em>Out of memory</em> error from PHP. Some are manual restarts and some are crashes like this:</p>

<pre><code>zend_mm_heap corrupted
12] [notice] Child 2524: Child process is exiting
[Mon Jan 09 19:45:12 2012] [notice] Parent: child process exited with status 1 -- Restarting.
[Mon Jan 09 19:45:13 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Mon Jan 09 19:45:13 2012] [notice] Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 configured -- resuming normal operations
[Mon Jan 09 19:45:13 2012] [notice] Server built: Sep 24 2011 00:32:50
[Mon Jan 09 19:45:13 2012] [notice] Parent: Created child process 6256
[Mon Jan 09 19:45:13 2012] [notice] Disabled use of AcceptEx() WinSock2 API
[Mon Jan 09 19:45:13 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Mon Jan 09 19:45:14 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Child process is running
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Acquired the start mutex.
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Starting 400 worker threads.
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Listening on port 443.
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Listening on port 80.
</code></pre>

<p><strong>Update #2:</strong> ... and the ODBC extension is logging the following error:</p>

<pre><code>No se puede cargar el controlador especificado debido al error del sistema  8 (Oracle in instantclient_11_2)
</code></pre>

<p>... where <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx" rel="nofollow">system error 8</a> maps to:</p>

<blockquote>
  <p><code>ERROR_NOT_ENOUGH_MEMORY 8 (0x8)</code> Not enough storage is available to process this command.</p>
</blockquote>
