php-fpm request_terminate_timeout 和php.ini的max_execution_time(php-fpm request_ terminate_ Timeout and PHP Max of ini_ execution_ time)

web请求php执行时间受到2方面控制,一个是php.ini的max_execution_time(要注意的是sleep,http请求等待响应的时间是不算的,这里算的是真正的执行时间),另一个是php-fpm request_terminate_timeout 设置,这个算的是请求开始n秒。

request_terminate_timeout引起的资源问题

request_terminate_timeout的值如果设置为0或者过长的时间,可能会引起file_get_contents的资源问题。
如果file_get_contents请求的远程资源如果反应过慢,file_get_contents就会一直卡在那里不会超时。我们知道php.ini
里面max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm)
中,该参数不会起效。

真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的request_terminate_timeout参数。
request_terminate_timeout默认值为 0 秒,也就是说,PHP 脚本会一直执行下去。
这样,当所有的 php-cgi 进程都卡在 file_get_contents() 函数时,这台 Nginx+PHP 的 WebServer 已经无法再处理新的 PHP 请求了

————————

PHP execution time of web requests is controlled by two aspects, one is PHP Max of ini_ execution_ Time (note that sleep, the waiting time for the response of HTTP request is not counted, here is the real execution time), and the other is PHP FPM request_ terminate_ Timeout setting, which counts N seconds from the beginning of the request.

request_terminate_timeout引起的资源问题

request_ terminate_ If the value of timeout is set to 0 or too long, it may cause file failure_ get_ The resource problem of contents.
If file_ get_ If the response of remote resources requested by contents is too slow, file_ get_ Contents will always be stuck there without timeout. We know PHP ini
Inside Max_ execution_ Time can set the maximum execution time of PHP script, but in PHP CGI (PHP FPM)
This parameter does not take effect in.

PHP FPM is the one that can really control the maximum execution time of PHP scripts Request in conf configuration file_ terminate_ Timeout parameter.
request_ terminate_ The default value of 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 file_ get_ When using the contents() function, the nginx + PHP webserver can no longer process new PHP requests