Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

We have a web server running a PHP application to serve customers.

  • PHP 4
  • 3 GB memory
  • Centos
  • Apache HTTP server.

As our customer load has increased, we are having server memory issues. Sooner or later, we need to restart the HTTP service to release the memory (probably 5 times a day).

We can tell from top that most of the HTTP processes are fine, only using a little memory, but there are about 3-4 HTTP processes that are taking 80% of the memory and almost zero CPU usage. It looks like dead processes, but they don't release memory until we restart the HTTP service.

We suspect some part of our PHP code isn't working well and causing huge memory usage, then hanging there. Is there a PHP setting somewhere we can set that will terminate the process and free up the memory after, say, 5 minutes idle? This is a short term solution, we will have to find out what code is doing this -- hard to find, though.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

There are a couple lines in your php.ini file that are relevant. One is the memory_limit which defines how much RAM any given php script is allowed to eat through, the other is max_execution_time which defines how much CPU time it gets before being killed off. Be aware that this latter time is based on CPU time not clock time, so if it isn't using any CPU it might not ever add up.

Also as you noted these are temporary hacks to mitigate a mis-behaving app, not a real fix. You might find strace useful to figure out exactly what the memory-hogging processes are up to.

share|improve this answer

In Linux, memory "cached" is free memory used to cache files. Linux uses as much memory as possible to speed up io with block devices. If you programs need real memory, linux will free cache pages before going to swap.

For example, now on my laptop, I have 90% of memory used, but 0% of swap. This is because the real used memory is only 20%.

Top will tell you how much memory is going to buffers. If this number is big, this means that the used memory is only for cache, not real used memory. During the day, you can check how much memory is going to swap (your real problem).

if you use the command 'free' , you have a line with "-/+ buffers/cache" , with your real used memory.

You can read about /proc/sys/vm/swappiness to control how much memory will go to swap or to cache files.

share|improve this answer

Apache has a MaxRequestsPerChild directive which can be instructed to recycle workers (the processes that embed mod_php) after a certain number of requests have been processed.

share|improve this answer

Your Answer

 
discard

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.