Random "PHP Fatal error: Out of memory" errors - php

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:
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)
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).
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.

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 ;)

Related

Apache - Parent: Received shutdown signal

I tried to set CakePHP in localhost. It works great except when the page goes to the one that need to read the database.
It just shows:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#dummy-host.example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Here's the error log:
[Thu May 09 12:07:44 2013] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Thu May 09 12:07:44 2013] [notice] Child 844: Exit event signaled. Child process is ending.
[Thu May 09 12:07:45 2013] [notice] Child 844: Released the start mutex
[Thu May 09 12:08:00 2013] [notice] Child 844: All worker threads have exited.
[Thu May 09 12:08:00 2013] [notice] Child 844: Child process is exiting
[Thu May 09 12:08:00 2013] [notice] Parent: Child process exited successfully.
Warning: DocumentRoot [C:/apache2/docs/dummy-host.example.com] does not exist
Warning: DocumentRoot [C:/apache2/docs/dummy-host2.example.com] does not exist
[Thu May 09 12:08:01 2013] [notice] Apache/2.2.22 (Win64) PHP/5.3.13 configured -- resuming normal operations
[Thu May 09 12:08:01 2013] [notice] Server built: May 13 2012 19:41:17
[Thu May 09 12:08:01 2013] [notice] Parent: Created child process 2504
Warning: DocumentRoot [C:/apache2/docs/dummy-host.example.com] does not exist
Warning: DocumentRoot [C:/apache2/docs/dummy-host2.example.com] does not exist
Warning: DocumentRoot [C:/apache2/docs/dummy-host.example.com] does not exist
Warning: DocumentRoot [C:/apache2/docs/dummy-host2.example.com] does not exist
[Thu May 09 12:08:01 2013] [notice] Child 2504: Child process is running
[Thu May 09 12:08:01 2013] [notice] Child 2504: Acquired the start mutex.
[Thu May 09 12:08:01 2013] [notice] Child 2504: Starting 64 worker threads.
[Thu May 09 12:08:01 2013] [notice] Child 2504: Starting thread to listen on port 80.
Most answer that I found in Google is asking us to edit C:\WINDOWS\System32\drivers\etc\hosts to only have one 127.0.0.1 localhost. Mine has been like that since the very beginning.
By the way, in the error log, it says C:/apache2/.... But in my C folder, that directory doesn't exist.
I use WAMP Server if that matter.
Any solution?
Thank you
I change my server from WAMP to XAMPP and now it works okay. Not sure what cause it.

APC crashes when user cache is used

I'm developing a PHP app and and want to cache some data in APC. APC is running and enabled, I can see statistics when I open apc.php which indicate that opcode caching works fine.
However, the apache process crashes whenever I try to use apc_store() or apc_add() to store some data.
This is on a Windows 7 Professional 64bit system and happens with both of these version combinations:
Apache 2.2.21, PHP 5.3.9, APC 3.1.6
Apache 2.2.22, PHP 5.3.13, APC 3.1.9
With the first configuration, the crash happens immediately and this in the apache error log:
[Fri Jun 08 12:51:58 2012] [notice] Parent: child process exited with status 255 -- Restarting.
With second there is some delay and I get this:
[Fri Jun 08 16:18:48 2012] [notice] Child 5052: Exit event signaled. Child process is ending.
[Fri Jun 08 16:18:48 2012] [warn] (OS 995)Der E/A-Vorgang wurde wegen eines Threadendes oder einer Anwendungsanforderung abgebrochen. : winnt_accept: Asynchronous AcceptEx failed.
[Fri Jun 08 16:18:48 2012] [warn] (OS 10038)Ein Vorgang bezog sich auf ein Objekt, das kein Socket ist. : setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed.
[Fri Jun 08 16:18:52 2012] [warn] pid file C:/wamp/bin/apache/apache2.2.22/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Fri Jun 08 16:18:52 2012] [notice] Apache/2.2.22 (Win64) PHP/5.3.13 configured -- resuming normal operations
What can be done to fix this?
Seems like the array I wanted to store contained a native resource, and that caused the crash.
Using serialize() before storing it and unserialize() afterwards fixed the problem.

APACHE Crashing: Parent: child process exited with status 3221225477 -- Restarting

My following setup is Xampp 1.7.7 and here is the info for everything in that package:
- Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
I'm running the server on Windows XP SP3 32 bit OS, 4 gigs of ram, Quad Core.
The issue I'm having in my apache error log file is:
[Tue Apr 24 15:55:55 2012] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Tue Apr 24 15:55:57 2012] [notice] Digest: generating secret for digest authentication ...
[Tue Apr 24 15:55:57 2012] [notice] Digest: done
[Tue Apr 24 15:55:59 2012] [notice] Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Tue Apr 24 15:55:59 2012] [notice] Server built: Sep 10 2011 11:34:11
[Tue Apr 24 15:55:59 2012] [notice] Parent: Created child process 776
[Tue Apr 24 15:56:00 2012] [notice] Disabled use of AcceptEx() WinSock2 API
[Tue Apr 24 15:56:01 2012] [notice] Digest: generating secret for digest authentication ...
[Tue Apr 24 15:56:01 2012] [notice] Digest: done
[Tue Apr 24 15:56:02 2012] [notice] Child 776: Child process is running
[Tue Apr 24 15:56:02 2012] [notice] Child 776: Acquired the start mutex.
[Tue Apr 24 15:56:02 2012] [notice] Child 776: Starting 350 worker threads.
[Tue Apr 24 15:56:02 2012] [notice] Child 776: Listening on port 443.
[Tue Apr 24 15:56:02 2012] [notice] Child 776: Listening on port 80.
This seems to occur sporadically throughout the day and I even tried using Win32DisableEx, EnableIMAP Off and EnableSendFile Off in the apache conf file. I also tried copying the libmysql.dll file to the system32 and apache/bin folders with no avail.
If anyone knows other reasons this error for the child process exiting and causing apache to crash, info would be greatly appreciated. If any additional log files are needed please let me know.
Tks,
Shane.
The error code 3221225477 is 0xC0000005 in hex, which on Windows is:
#define STATUS_ACCESS_VIOLATION ((NTSTATUS)0xC0000005L)
Access violation is Windows' version of "segmentation fault", which simply said means that the program tried to access a memory which is not allocated. This can happen for a lot of different reasons, but mostly (if not always) is a bug in the program.
Now, my guess for your situation, is that there is either a bug in PHP or in one of PHP's extensions or in Perl or some Perl application. Apache itself is usually very stable, but if you use some unusual extension, it might be the cause, too.
I would suggest updating all your configuration to latest versions. If you want to find the source of the problem for sure, run Apache inside a debugger, like Visual Studio or OllyDbg. When the exception (access violation) happens, it will stop execution (instead of restarting) and you'll see in which module it is.
Also take a look in the access log, if there is a suspicious request with the same timestamp as the error. But it may happen that the crash happens before the request is saved in the logfile.

Performance issue with php/apache/windows. Connection reset

I'm having a rather big problem with a site performance. It's a php site on Apache on Windows Server 2003.
Web site is basically crashing with 'connection was reset' or 'cannot load web page' quite often. httpd process in Windows takes about 100mb on normal traffic, having about 1gb of memory still free
This is first time I host a php site on Windows (WIndows was requirement in this case) and I'm not sure what are my options
Thanks
Apache log is displaying the following (sorry for pasting it like that, couldn't do it as 'code block' from some reason. This surely doesn't look right. Any ideas what could be going on?
[Tue Nov 08 16:44:43 2011] [notice] Parent: Received restart signal --
Restarting the server.
[Tue Nov 08 16:44:43 2011] [notice] Child 2072: Exit event signaled.
Child process is ending.
httpd.exe: Could not reliably determine the server's fully qualified
domain name, using 192.168.67.1 for ServerName
[Tue Nov 08 16:44:44 2011] [notice] Apache/2.2.17 (Win32)
mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.2.17 configured -- resuming normal
operations
[Tue Nov 08 16:44:44 2011] [notice] Server built: Oct 18 2010 01:58:12
[Tue Nov 08 16:44:44 2011] [notice] Parent: Created child process 7692
httpd.exe: Could not reliably determine the server's fully qualified
domain name, using 192.168.67.1 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified
domain name, using 192.168.67.1 for ServerName
[Tue Nov 08 16:44:44 2011] [notice] Child 2072: Released the start
mutex
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Child process is
running
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Acquired the start
mutex.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting 1000 worker
threads.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting thread to
listen on port 2090.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting thread to
listen on port 8011.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting thread to
listen on port 8080.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting thread to
listen on port 443.
[Tue Nov 08 16:44:44 2011] [notice] Child 7692: Starting thread to
listen on port 80.
[Tue Nov 08 16:44:45 2011] [notice] Parent: child process exited with
status 0 -- Restarting.
httpd.exe: Could not reliably determine the server's fully qualified
domain name, using 192.168.67.1 for ServerName
Windows event viewer is throwing the following
Error - VsJITDebugger. An unhandled win32 exception occurred in httpd.exe [4416]. Just-In-Time debugging this exception failed with the following error: Debugger could not be started because no user is logged on.
Can anyone help with this?
That '[notice] Parent: child process exited with status 0 -- Restarting' is describing the issue here. Tho it describes it in vary vague way. Server is basically restarting on it's own every few minutes. I took the site down with a holding page and the error and restart ddidn't occure. I added an html page and bombed it with combinations of requests using AB. It would always crash at requests close to number of ThreadsPerChild specified in mpm config, which I have set to 1000. Each crash followed with an error
apr_socket_recv: An existing connection was forcibly closed by the remote host.
(730054)
That error only displays when benchmarking. Nothing like that appears in apache log. As soon I switch the site back live, it starts to crash every few minutes. The site generates about 100 requests per page and is also using 2-3 ajax calls per page (while loading)
I spent hours searching the web for possible solutions. Found nothing that fits. I'm completely out of options. I'm not even experienced running apache on windows as during 5 years I work in the business I never had to run php sites on Windows. I haven't seen such error on linux neither
There are two places where you should have a look:
Regular Apache logs, located in the logs folder inside Apache installation.
Windows event viewer, located in Windows control panel
In particular, the second one will log Apache crashes and will possibly reveal additional details.

The infamous Apache error "Parent: child process exited with status 3221225477"

I've read some questions and responses related to the infamous Apache error
Apache error [notice] Parent: child process exited with status 3221225477 — Restarting
But nothing could help me so far. What I'm asking to you is if I used a Linux version, could the script crash Apache for the same reason?
By the way if anyone has any suggestion for my case here is Apache's error.log
[Mon Aug 08 14:31:44 2011] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Mon Aug 08 14:31:44 2011] [crit] (22)Invalid argument: unable to replace stderr with error_log
[Mon Aug 08 14:31:44 2011] [crit] (2)No such file or directory: unable to replace stderr with /dev/null
[Mon Aug 08 14:31:44 2011] [notice] Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8c mod_autoindex_color PHP/5.1.6 configured -- resuming normal operations
[Mon Aug 08 14:31:44 2011] [notice] Server built: Aug 13 2006 19:16:43
[Mon Aug 08 14:31:44 2011] [notice] Parent: Created child process 4364
[Mon Aug 08 14:31:45 2011] [notice] Child 4364: Child process is running
[Mon Aug 08 14:31:45 2011] [notice] Child 4364: Acquired the start mutex.
[Mon Aug 08 14:31:45 2011] [notice] Child 4364: Starting 250 worker threads.
[Mon Aug 08 14:31:45 2011] [notice] Child 4364: Starting thread to listen on port 8088.
[Mon Aug 08 14:31:45 2011] [notice] Child 4364: Starting thread to listen on port 8086.
I can't understand why moving dlls around the filesystem solve most problems and all the suggestions in the related questions which were about moving libraries didn't work for me.
I'm running an old XAMPP release with PHP 5.1.6 (XAMPP for Windows 1.5.4) and working with Doctrine ORM (Yes, I'm aware that Doctrine requires PHP 5.2.3+).
I've just had this same problem on a WAMP installation. I tracked it down to a bit of my own rubbish code. I had a method calling itself.
Here's an example:-
<?php
echo "Welcome to stupid class!";
class stupid_class {
public $example_data;
function stupid_function($Data) {
self::stupid_function($Data);
if($Data=="Hello") return true;
else die("Incorrect data passed through.".$Data."<br />");
}
}
$myClass = new stupid_class();
$myvalue = $myClass->stupid_function("Hello");
?>
I know this is hardly an ideal example of great code, (it was actually a typo) but I would have expected there to be some error thrown before getting a 'connection was reset' message.
So I guess an answer would be, check through all your methods to make sure that you're not calling one infinitely.
I hope this helps someone to figure out why this is happening in PHP, Apache.
Cheers
Tee
In my case it was the php extension APC (php_apc.dll, 3.1.10-5.4-vc9-x86, threadsafe), which caused the error.
I used XAMPP 1.8.2 with PHP 5.4.19 and Apache 2.4.4
Since it could be caused by another extension as well, it might be a good starting point to restore the original php.ini from the xampp distribution. If this one works well, try to change it line by line to your desired configuration (starting with the extension list).

Categories