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

There are several discussions complaining high memory usage of PHP-FPM, without any practical approach to overcome. As I explored the problem with numerous tests, the problem is related to the age of PHP-FPM age.

Imagine we have pm.max_children = 10, and have a PHP script consuming 10M memory. One expects needing 100MB of MB. This is correct for the first 10 processes. After processing 20 PHP scripts, the system memory usage is 200MB, which means that the memory consumed during the first 10 processes have not been freed.

This will increase the memory usage until reaching pm.max_requests when PHP-FPM processes are reset.

NOTE: This was just a roughly simplified example for clarification, and not actual behavior. In real world, this happens sometimes. Normally, at the end of a PHP script, the memory consumed by PHP will be automatically freed. In PHP-FPM, this memory sometimes (I don't know when) will not be freed.

This means that for processing similar scripts (using 10MB of memory) with

pm.max_children = 10
pm.max_requests = 100

You do not need 100MB or 1000MB of memory; but something in between. In other words, footprints of some PHP previous processes remain on the PHP-FPM children.

In agreement with this theory, the high memory usage of PHP-FPM will be overcome by reducing pm.max_requests, but it is not the ultimate solution, and we need to find an approach to free the effects of previous PHP processes on the PHP-FPM children. Any idea?

share|improve this question
It is true that the memory consumption of long-running php-fpm processes increases. But the ratio you are describing sounds far too much. I would suggest checking your scripts and included php modules for memory leaks. Potential culprits might include low-level stuff like xdebug or some unfortunate situations with code caches like APC. – Martin Jun 17 '13 at 11:24

Without knowing exactly what kind of app you're running, it's hard for us to say what you should do. But, have considered using the ondemand process manager? It'll kill off processes after N time, thus keeping your memory freer, than the dynamic or static you're probably using.

share|improve this answer
ondemand is an option which is not popular; but sometimes very useful (but not always as it is slower than dynamic when PHP-FPM is always ready to server). This is not a real PHP script. I used to test typical PHP scripts to explore the issues (not my own issues), as there are many complains. I used standard PHP scripts like wordpress. – All Apr 3 '12 at 13:10
If you need to use dynamic then, there are timeouts for the processes, you can change those around and they'd die off faster/slower depending on your needs. – Vid Luther Apr 3 '12 at 14:21

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.