I'm running a CentOS 5.3 server with a basic LAMP stack. I've optimized LAMP and my code to run efficiently as possible, but Apache has a memory leak somewhere that kills my server every hour or so. What is the best way to write a script that will monitor the memory usage and if it peaks over, say, 450MB kill all the Apache processes and restart Apache. I know C++/PHP and basic Linux server administration but I'm not familiar with Perl or bash scripting. I'd be open to learn any solutions, though, as a temporary solution while I find the issue.
Asked
Active
Viewed 1,500 times
2 Answers
1
Monit is a straightforward server-monitoring utility that can do this sort of thing.

Josh Kelley
- 983
- 1
- 7
- 17
-
Thanks, that's exactly what I was looking for. I'll try it out and see if it works. – May 13 '10 at 18:15
0
Try setting the MaxRequestsPerChild
variable in Apache, which will cause it to kill and start its children after they have served the specified number of requests. In mod_php, this can be as low as 100.
PHP (especially mod_php) is known to do this. Alternatives include running PHP under FastCGI, which will prevent Apache from restarting and only restart the PHP interpreters.
You should also insure that you always have RAM available. If this means less Apache forks running, then so be it. Clamp down on ServerLimit

Yann Ramin
- 201
- 1
- 3
-
My machine has 500MB of RAM and a dual core P4 CPU, and my Apache processes are running at 28MB tops. I have about 5 connections per second on average. I have prefork set up and this is what my current config looks like: http://pastebin.org/230672 – May 13 '10 at 17:45