0

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. But the issue is that the lowest triggers first so 600s never applies which I don't expect.

Is it possible to retain request_terminate_timeout globally while setting a higher value for maximum execution time in individual PHP files?

revo
  • 47,783
  • 14
  • 74
  • 117

2 Answers2

3

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() .

The set_time_limit should only "overwrite" the max_execution_time directive, because

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:

should be used when the 'max_execution_time' ini option does not stop script execution for some reason.

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).

Using max_execution_time in place of request_terminate_timeout (but using it to the real, maximum upper-bound), should solve the problem.

The max_execution_time description in the official documentation has an hint about this common problem, that is:

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

Note: Some variables in this equation can be even webserver-dependent (example: read timeout).

Lorenzo S
  • 1,397
  • 13
  • 25
  • 1
    Actually I stopped using `request_terminate_timeout` and stuck with `max_execution_time` but I'm afraid what will happen to a php-fpm process when `max_execution_time` is reached but `request_terminate_timeout` has a value higher than that whether it remains an active process or not. – revo Oct 31 '18 at 08:00
0

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.

That is why the answer is "NO"

In my 'php-fpm.conf' "request_terminate_timeout" is not found. Default value: 0. A value of '0' means 'Off'.

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191
  • What if you are running php in the command line and stiill gets killed by Max Execution Time? No apache in this case... How to get rid of this limit if you want to use PHP just as a comand line language? – Sergio Abreu Aug 25 '23 at 12:00