Home  >  Article  >  Backend Development  >  Understanding of PHP-FPM parameters

Understanding of PHP-FPM parameters

王林
王林forward
2019-08-21 10:01:331715browse

process_control_timeout

English explanation

process_control_timeout mixedTime limit for child processes to wait for a reaction on signals from master.
Available units: s(econds), m(inutes), h(ours), or d(ays) Default Unit: seconds. Default value: 0.

Chinese explanation

process_control_timeout
 mixed
设置子进程接受主进程复用信号的超时时间。可用单位:s(秒),m(分),h(小时)或者 d(天)。默认单位:s(秒)。默认值:0(关闭)。

There is something inappropriate in the Chinese translation. The English explanation does not specify this The signal is a multiplexed signal.

My understanding:

Processing requests

In principle, php-fpm will choose the idle fastcgi process to process Before processing the request, php-fpm will send a signal to fastcgi to prepare the fastcgi process to accept the request processing. However, the fastcgi process is not always able to handle the request, that is, it cannot always respond to the signal (such as suspended animation). At this time, you need to set the time php-fpm leaves for the fastcgi process to respond to the signal. If it times out, php -fpm will think of other ways (such as selecting other fastcgi processes), this is the role of the process_control_timeout parameter.

php-fpmPerformreload

process_control_timeout = 10

<?php 
sleep(50);echo 1;sleep(20);    
//没有这个sleep,reload会立即生效echo 2;

When the browser accesseshttp://localhost, perform php-fpmsmoothingreload, after the fastcgi signal receives the shutdown process signal, the first sleep function will return directly, but The second sleep is still executing. Therefore, php-fpm will be stuck by this old fastcgi process for 10 seconds. After that, a smooth restart can be completed.

request_terminate_timeout

Inphp-fpm.confThe description in the file is as follows:

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the &#39;max_execution_time&#39; ini option
; does not stop script execution for some reason. A value of &#39;0&#39; means &#39;off&#39;.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0

The translation is:
request_terminate_timeoutThe parameter sets the timeout for processing a single request. After that, the worker process will be killed. Lose. This option should be used if the max_execution_time option in the php.ini file does not stop the script from running for some reason. The default value is 0, which means this option is turned off.

As mentioned above, request_terminate_timeout sets the timeout of the request, and max_execution_time in the php.ini configuration. According to the following explanation in the manual, the script is Maximum execution time allowed.

max_execution_time
 integer
这设置了脚本被解析器中止之前允许的最大执行时间,单位秒。 这有助于防止写得不好的脚本占尽服务器资源。 默认设置为 30。 从命令行运行 PHP 时,默认设置为 0。
最大执行时间不会影响系统调用和系统操作等。更多细节参见 set_time_limit()。
在 安全模式 下你不能通过 ini_set() 来修改此设置。 唯一的解决方法是关闭安全模式或者在 php.ini中修改时间限制。
你的 web 服务器也可以有其他超时设置,也有可能中断 PHP 的执行。 Apache 有一个 Timeout 指令,IIS 有一个 CGI 超时功能。 他们默认都是 300 秒。更多具体信息参见你的 web 服务器的文档。

The difference is as follows:

After timeout, request_terminate_timeout will return 502Bad Gateway, and max_execution_time will throwFatalError.

max_execution_time does not include the time for system calls such as using system(), sleep(), stream operations, database operations, etc., so it is relatively useless, while request_terminate_timeout will Contains the complete request time of the program.

In addition, turning on request_terminate_timeout will not invalidate max_execution_time. Whoever reaches the timeout first will take effect.

For more related PHP issues, please visit the PHP Chinese website: https://www.php.cn/

The above is the detailed content of Understanding of PHP-FPM parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:PHPStudy. If there is any infringement, please contact admin@php.cn delete