简体   繁体   English

处理 PHP-FPM 和 PHP 文件设置的执行时间

[英]Handling execution time set by PHP-FPM and PHP file

I have set request_terminate_timeout directive in PHP-FPM pool configuration file which is currently 100s and I'm setting set_time_limit(600) for an individual PHP file.我在 PHP-FPM 池配置文件中设置了request_terminate_timeout指令,当前为100s ,我正在为单个 PHP 文件设置set_time_limit(600) But the issue is that the lowest triggers first so 600s never applies which I don't expect.但问题是最低触发器首先触发,所以600s永远不会适用,这是我没想到的。

Is it possible to retain request_terminate_timeout globally while setting a higher value for maximum execution time in individual PHP files?是否可以在全局保留request_terminate_timeout的同时为单个 PHP 文件中的最大执行时间设置更高的值?

I have fronted a similar problem before.我以前也遇到过类似的问题。 Not completely sure it can fit with your problem, but I have tried to document everything just to be sure to give "safe" hints.不完全确定它是否适合您的问题,但我已尝试记录所有内容以确保提供“安全”提示。

The brutal answer to your question I guess it's NO, because the directives you specify in php-fpm.conf are mostly not changeable from ini_set() , and set_time_limit is a almost nothing more than a convenience wrapper on ini_set() .对您的问题的残酷回答我猜它是否定的,因为您在php-fpm.conf中指定的指令大多不能从ini_set()更改,而set_time_limit几乎只是ini_set()上的便利包装器

The set_time_limit should only "overwrite" the max_execution_time directive, because set_time_limit应该只“覆盖” max_execution_time指令,因为

they only affect the execution time of the script itself它们只影响脚本本身的执行时间

(there is a specific note in the official documentation ). 官方文档中有具体说明)。

On the other hand, request_terminate_timeout is related to FPM, so we are talking about the process management level here:另一方面, request_terminate_timeout和FPM有关,所以这里说的是进程管理级别:

should be used when the 'max_execution_time' ini option does not stop script execution for some reason.当'max_execution_time' ini 选项由于某种原因没有停止脚本执行时应该使用。

So, to try answering the question, I think the problem is that you are trying to mix something handled by FPM ( request_terminate_timeout ) and something handled by PHP itself ( max_execution_time ).因此,为了尝试回答这个问题,我认为问题在于您试图混合 FPM 处理的内容( request_terminate_timeout )和 PHP 本身处理的内容( max_execution_time )。

Using max_execution_time in place of request_terminate_timeout (but using it to the real, maximum upper-bound), should solve the problem.使用 max_execution_time 代替 request_terminate_timeout (但将其用于真实的最大上限)应该可以解决问题。

The max_execution_time description in the official documentation has an hint about this common problem, that is:官方文档中的max_execution_time描述有一个关于这个常见问题的提示,即:

Your web server can have other timeout configurations that may also interrupt PHP execution.您的 Web 服务器可以有其他可能会中断 PHP 执行的超时配置。 Apache has a Timeout directive and IIS has a CGI timeout function. Apache 有一个 Timeout 指令,而 IIS 有一个 CGI 超时功能。 Both default to 300 seconds.两者都默认为 300 秒。 See your web server documentation for specific details.有关特定详细信息,请参阅您的 Web 服务器文档。

Note: Some variables in this equation can be even webserver-dependent (example: read timeout).注意:此等式中的某些变量甚至可能与网络服务器相关(例如:读取超时)。

max_execution_time from PHP should be lower than request_terminate_timeout from njinx because PHP will trigger an exception and you will be able to catch it and do something about it, when request_terminate_timeout will annoy users of your web site without giving you any feedback.来自PHPmax_execution_time应该低于来自njinxrequest_terminate_timeout因为 PHP 会触发一个异常并且你将能够捕获它并对其进行处理,当request_terminate_timeout会惹恼你网站的用户而不给你任何反馈时。

That is why the answer is "NO"这就是为什么答案是“不”

In my 'php-fpm.conf' "request_terminate_timeout" is not found.在我的“php-fpm.conf”中找不到“request_terminate_timeout”。 Default value: 0. A value of '0' means 'Off'.默认值:0。“0”值表示“关闭”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM