Home > Article > Backend Development > Detailed explanation of php-fpm startup parameters and important configurations
Detailed explanation of php-fpm startup parameters and important configurations
Agree several directories
One, the startup parameters of php-fpm
Second, detailed explanation of important parameters of php-fpm.conf
Three, common errors and solutions
1. Resource problems caused by request_terminate_timeout
If the value of request_terminate_timeout is set to 0 or too long, it may cause resource problems in file_get_contents.
If the remote resource requested by file_get_contents responds too slowly, file_get_contents will always be stuck there without timing out. We know that max_execution_time in php.ini can set the maximum execution time of PHP scripts, but in php-cgi (php-fpm), this parameter will not take effect. What can really control the maximum execution time of PHP scripts is the request_terminate_timeout parameter in the php-fpm.conf configuration file.
The default value of request_terminate_timeout is 0 seconds, which means that the PHP script will continue to execute. In this way, when all php-cgi processes are stuck in the file_get_contents() function, this Nginx+PHP WebServer can no longer handle new PHP requests, and Nginx will return "502 Bad Gateway" to the user. Modifying this parameter is necessary to set the maximum execution time of a PHP script, but it only treats the symptoms rather than the root cause. For example, change it to 30s, if file_get_contents() occurs When retrieving web page content is slow, this means that 150 php-cgi processes can only handle 5 requests per second. It is also difficult for WebServer to avoid "502 Bad Gateway". The solution is to set request_terminate_timeout to 10s or a reasonable value, or add a timeout parameter to file_get_contents.
Our current solution is to set this value as large as possible to reduce the number of times PHP-CGI re-SPAWNs as much as possible, while also improving overall performance. In our own actual production environment, we found that the memory leak was not obvious, so we set this value very large (204800). Everyone should set this value according to their actual situation and cannot blindly increase it.
Having said that, the purpose of this mechanism is only to ensure that PHP-CGI does not occupy excessive memory. Why not deal with it by detecting memory? I very much agree with what Gao Chunhui said, restarting the PHP-CGI process by setting the peak intrinsic usage of the process would be a better solution.
3, php-fpm's slow log, debug and exception troubleshooting artifact: request_slowlog_timeout sets a timeout parameter, slowlog sets the storage location of the slow log1