Home > Article > Backend Development > php process does not release memory
Solve the problem that the php-fpm process does not release memory
##By reducing php- The total number of fpm processes can be used to reduce the memory usage of php-fpm. During actual use, it was found that the php-fpm process still has the problem of long-term memory occupation without releasing it. The solution is to reduce the number of pm.max_requests. (Recommended learning: PHP programming from entry to proficiency)
Maximum number of requests max_requests, that is, when the number of requests processed by a PHP-CGI process accumulates to max_requests, it will automatically restart This process achieves the purpose of releasing memory. Take the VPS host setting of 1GB memory as an example (if the value you set does not reach the free memory, you can continue to lower it):pm.max_requests = 500When the php-fpm process reaches the value set by pm.max_requests, it will Restart the process, thereby freeing up memory. The picture below is the result after my test. It can be seen that the php-fpm process was forcibly terminated and the memory was released. For large memory and concurrency and availability requirements, it is recommended to use the static management mode with the largest pm.max_children. If it is a server with small memory, it is recommended to use dynamic or ondemand mode and reduce the number of pm.start_servers and pm.max_spare_servers processes.
The above is the detailed content of php process does not release memory. For more information, please follow other related articles on the PHP Chinese website!