If you are really getting this error and finding the solution to the problem. You might have already explored the internet and tried many ways to solve this. Well this isn’t as tricky as it seems to be. But when we try thousands time without any luck, you start to feel overwhelmed by situation. Well no frustration any more. I am here as last resort to the problem. Let’s move towards the solution and see why you are seeing too many process of php-fpm in the ssh console .

Basic Understanding of the situation

PHP-FPM (FastCGI Process Manager) is responsible for handling PHP requests in a FastCGI environment. When a request comes in, PHP-FPM spawns a worker process to process that request. However, if the request fails for some reason, such as a syntax error in the PHP code or a timeout, PHP-FPM may still create multiple processes due to its process management configuration.

Reason for failed requests

  1. Process Management Configuration: PHP-FPM allows you to configure how it manages worker processes through directives in its configuration file (usually located at /etc/php-fpm.conf or /etc/php/<version>/fpm/php-fpm.conf). The relevant directives are pm.max_children, pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers. If these values are set too high, PHP-FPM will create more worker processes than necessary, even for failed requests.
  2. Script Timeout Settings: If PHP scripts have a long execution time limit or the request handling process is taking longer than expected, PHP-FPM may create additional processes to handle new requests. This can happen even if the original request has failed or timed out.
  3. Incorrect PHP Error Handling: If PHP-FPM is not properly configured to handle PHP errors, such as syntax errors or fatal errors, it may not terminate the worker process after encountering such errors. As a result, PHP-FPM continues to spawn new processes for subsequent requests, leading to an accumulation of processes.

Solution to the problem

Review and adjust the process management configuration (pm.max_children, pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers) to ensure that the number of worker processes is appropriate for your server’s resources and workload.

Set appropriate script timeout values (max_execution_time, max_input_time, etc.) in your PHP configuration to prevent requests from running excessively long.

Enable proper error handling and logging in PHP-FPM to identify and address any issues causing requests to fail. Make sure that PHP-FPM terminates worker processes after encountering fatal errors or other critical issues.

Heare are some links that might help to solve the problem.

https://stackoverflow.com/questions/31469119/

https://support.plesk.com/hc/en-us/articles/12387450677143-Plesk-hosted-site-uses-more-RAM-than-expected-too-many-PHP-FPM-child-processes

https://serverfault.com/questions/998677/php-fpm-creating-too-many-proccesses-eating-all-the-cpu

Final note

By fine-tuning these configurations and addressing any underlying issues, you can optimize the behavior of PHP-FPM and prevent it from creating excessive processes for failed requests. I hope you have got a needed direction regarding your problem. Let me know if you have any other question related to the problem or still unable to understand anything in specific. Thanks for your time. Have a nice day 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *