9

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:

[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

I'm confused for the following reasons:

  1. It is not the standard error message you get when memory_limit is reached:

    Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 800001 bytes)
    
  2. Whatever, memory_limit defaults to 256MB on the server and is set to 128MB on this app (thus 524,288 bytes should not be a problem).

  3. In the reported lines there's normally pretty innocent code, such as the start of function definitions...

    function linea($html){
    

    ... or foreach() loops of very small arrays:

    foreach($perfiles_basicos as $c => $v){
    

I think I've already discarded all the obvious stuff (I've even searched for the memory_limit 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.

Any hint or idea?


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

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.

Update #2: ... and the ODBC extension is logging the following error:

No se puede cargar el controlador especificado debido al error del sistema  8 (Oracle in instantclient_11_2)

... where system error 8 maps to:

ERROR_NOT_ENOUGH_MEMORY 8 (0x8) Not enough storage is available to process this command.

2
  • 3
    Have you checked the memory utilization on your system? OOM generally happens when the system cannot physically allocate the memory, not when PHP has reached it's limit for a request. Commented Jan 10, 2012 at 18:08
  • No framework, just vanilla PHP. I'll try to monitor system's memory. Commented Jan 11, 2012 at 8:18

1 Answer 1

10

I just did a quick search for "Out of memory" in the PHP tree and found that this error is triggered by the Zend Memory Manager if an internal allocation call (e.g. malloc) fails (see code).

So, yeah, sounds like the system went out of memory ;)

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, that's a simple and sensible explanation I hadn't even considered. Right now, the server is almost idle and task manager shows a wmicpa.exe process with an extremely high virtual memory usage. I'd better ask the system administrator.
I still have no clue about the exact reason for the errors but your answer and the "zend_mm_heap corrupted" messages in Apache's error log point to some sort of memory allocation problem beyond my reach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.