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
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
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
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?