Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from May 13 '10 at 19:45

This question came from our site for professional and enthusiast programmers.

Monit is a straightforward server-monitoring utility that can do this sort of thing.

share|improve this answer
Thanks, that's exactly what I was looking for. I'll try it out and see if it works. – Chris May 13 '10 at 18:15

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

share|improve this answer
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: – Chris May 13 '10 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.