Apache crashes due to PHP out of memory error

Apache crashes due to PHP out of memory error

by Mohan V -
Number of replies: 13

Apache crashes due to PHP out of memory error

I am running Moodle 1.9.2 on Intel xeon 5355 2.66 GHZ Dell server with 16 GB of memory in a single school with at mostly hundred students using Moodle at the same time.  Moodle website has about 12000 students and with 700 courses of  which  7000 active students and 300 active courses.

php.ini is configured:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 120 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 512M ; Maximum amount of memory a script may consume (16MB)

The underlying server architecture

 Consisting of Apache 2.2.3, PHP 5.2.3.3, and MySQL (5.0.45) with APC installed

 

Apache's error.log contains the following entry

Thu May 14 14:41:15 2009] [error] [client 172.19.101.74] PHP Fatal error:  Out of memory (allocated 6029312) (tried to allocate 58752 bytes) in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\moodle\\lib\\accesslib.php on line 129, referer: http://moodle.cwc.ac.uk/moodle/login/index.php

[Thu May 14 14:41:17 2009] [error] [client 82.11.3.224] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico

[Thu May 14 14:41:20 2009] [error] [client 82.11.3.224] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico

[Thu May 14 14:44:37 2009] [error] [client 82.1.153.63] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico

[Thu May 14 14:46:11 2009] [notice] Parent: Received restart signal -- Restarting the server.

[Thu May 14 14:46:11 2009] [notice] Child 1392: Exit event signaled. Child process is ending.

[Thu May 14 14:46:12 2009] [notice] Child 1392: Released the start mutex

[Thu May 14 14:46:13 2009] [notice] Child 1392: Waiting for 250 worker threads to exit.

[Thu May 14 14:46:13 2009] [notice] Child 1392: All worker threads have exited.

[Thu May 14 14:46:13 2009] [notice] Child 1392: Child process is exiting

[Thu May 14 14:46:15 2009] [notice] Apache/2.2.4 (Win32) PHP/5.2.3 mod_auth_sspi/1.0.4 configured -- resuming normal operations

[Thu May 14 14:46:15 2009] [notice] Server built: Jan  9 2007 23:17:20

[Thu May 14 14:46:15 2009] [notice] Parent: Created child process 4228

[Thu May 14 14:46:15 2009] [notice] Child 4228: Child process is running

[Thu May 14 14:46:15 2009] [notice] Child 4228: Acquired the start mutex.

[Thu May 14 14:46:15 2009] [notice] Child 4228: Starting 250 worker threads.

[Thu May 14 14:46:15 2009] [notice] Child 4228: Starting thread to listen on port 80.

but even with APC installed is crashing,  is there any way to configure Apache and PHP to avoid the crashes??

Thanks in advance for your help.

Average of ratings: -
In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Sylvio Runge -
update your WAMP software; see also
 http://moodle.org/mod/forum/discuss.php?d=90022

>with 16 GB of memory ?; does Windows with this RAM come clearly?
- windows-version?
- apache is 64bit?
- windows really uses all memory?

http://support.microsoft.com/?scid=kb%3Ben-us%3B888732&x=9&y=9




 S.


In reply to Sylvio Runge

Re: Apache crashes due to PHP out of memory error

by Mohan V -

Thanks sylvio for replying

Please see the attached image

The ram is clearly seen from the Windows task screen

Windows version 2003 Enterprise Edition 32bit

Apache 32 bit

Window still has about 14GB of free memory

Any help will be really useful

mo

Attachment memeory.jpg
In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Jade Tippett -
I had a similar problem. Apparently there are conflicts with Apache and PHP under Windows that result in memory not being released. Memory usage grows until it reaches a system maximum. Then PHP crashes which brings Apache down.

Several respondents suggested different combinations of Apache and PHP versions which seemed to eliminate the problem.

I took the quick and dirty route and used Scheduled Tasks to restart Apache twice a day. This eliminated the crashing, although if I watch the performance, memory usage still climbs between restarts.
In reply to Jade Tippett

Re: Apache crashes due to PHP out of memory error

by Mohan V -

Hi Jade

Thanks for your help

I think my manager does not like the idea of restarting it twice or even once a day. As he believes there might be users logged onto Moodle 5 am at dawn or even 2 am , 3 am so on.

I am still waiting for the answers  from somebody

Testing different combinations of Apache and PHP versions seems to be harder as it wont be same as testing it on Live server with thousands of users.

Mohan

In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Assuming you have the dreaded Apache memory leak problem do a forum search on those terms in this forum and in the Windows forum http://moodle.org/mod/forum/view.php?id=6799

I don't know the current status, but remember people having this problem eternally whereas other have found combinations of (W)AMP with zero problems.

So your choices are: a) find a safe combination b) switch to Unix ;)
In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Matt Clarkson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I suggest chainging MaxRequestsPerChild to 50 in your apache config. It might also be a good idea to try switcing Apache to prefork mode instead of theaded.

By default Apache will use the same child precesses forever which is great if you're serving up static HTML, but for PHP apps like moodle the Apache child processess will end up using heaps of memory, Setting MaxRequestsPerChild means that after x number or requests have been served by a child process it will be destroyed and replaced with a new one.
In reply to Matt Clarkson

Re: Apache crashes due to PHP out of memory error

by Doris Johnson -
Hi Matt, what file is the MaxRequestsPerChild in? I would like to try this. I realize this post is a little old.
In reply to Doris Johnson

Re: Apache crashes due to PHP out of memory error

by Henning Bostelmann -
Picture of Core developers Picture of Plugin developers
It's usually added in apache2.conf (in the default configuration, it will probably not be there at all, so it's assumed to be at its default value). See also the Apache documentation.
In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Jade Tippett -
When Apache restarts, from what I can tell, it simply stops receiving connections, clears all the requests it is serving, then stops and restarts in one operation. When it stops, it clears all buffers and releases all memory. Then it restarts. The whole process takes about 30 seconds or less for my server. From the user standpoint, only a momentary suspension, similar to a network glitch, is seen.
In reply to Jade Tippett

Re: Apache crashes due to PHP out of memory error

by Mohan V -

Hi Jade

many thanks for your reply

I was wondering if you know how to schedule the apache restart in Windows server 2003. I mean the command line script.

Thanks again

mo

In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Ben Steeples -
We restart Apache nightly, as part of its daily maintenance.

Essentially, we schedule a batch file to do the following:
  • Copy maintenance.html into place, in order to put Moodle into Maintenance Mode.
  • Run various user/enrolment/other scripts to keep Moodle healthy.
  • NET STOP APACHE2, to stop Apache service.
  • NET START APACHE2, to start Apache service.
  • Remove maintenance.html to return Moodle to service.
In reply to Mohan V

Re: Apache crashes due to PHP out of memory error

by Jade Tippett -
I just created a batch file: apacheClearMem.bat in ..\apache\bin:

It contains a single line:

apache.exe -k restart

If apache\bin in in the path (it should be), you can create a Scheduled Task (Programs|Accessories|System Tools in the Start menu).

Schedule your batch file to run as often as you need to. I try to run it before school and at lunch.

--j
In reply to Jade Tippett

Re: Apache crashes due to PHP out of memory error

by Mohan V -

Thank you guys

for some reason I had to use

httpd.exe -k restart -n apache2 (service name)

Thank you