Controlling Apache’s resource usage

One of the servers I’m maintaining was acting strange due to a badly programmed PHP page. It would cause the server to drop network connections every once in a while and the only option for fixing it was to have it hard rebooted. The initial suspect was the distribution since I don’t remember ever seeing a stable, trouble-free server running it, but it looks like a bit of both. Besides, changing the OS was not an option.

I started looking at ways to fix it (without switching the distribution) and found this file (doesn’t exist on Slackware):


This seemed to have everything I could use to contain Apache and PHP and keep the rest of the server from coming down, but digging a little deeper, I found these settings within Apache’s docs:

 RLimitCPU 100 100 RLimitMem 10000000 10000000 RLimitNProc 20 20 

The first limits the number of CPU cycles a child process uses, the second limits it’s memory usage and the third limits the processes it can spawn. Though I can’t confirm if they solved the issue yet, they look like very useful options. Should come in handy while bolting down Apache.