I have a combination of Nginx and PHP-FPM, and I want to set the max execution time on the PHP level to be the same as on Nginx. So I add max_execution_time=30 but it does not work.
If I create an endpoint with the logic like this:
foreach (range(1, 50) as $i) {
sleep(1);
if ($i > 40) {
$this->logger->error('Processing request', ['i' => $i]);
continue;
}
if ($i > 20) {
$this->logger->warning('Processing request', ['i' => $i]);
continue;
}
$this->logger->info('Processing request', ['i' => $i]);
}
$this->logger->info('Request processed');
and running that script after 30 seconds I see 504 from Nginx, but PHP still processing the request and writing logs. What I’m doing wrong?
Update: sleep here is just an example, on production for long-running endpoints I also see the same issue, when Nginx already interrupted execution but PHP still processing either, executing some query or something else, and I do not want PHP to be busy if it should not be… I know that can be handled on the FPM side by request_terminate_timeout, it’ll SIGTERM process, but in that case, new issues appearing related to PHP workers respawn that lead to an increased amount of 504 that even not reaching PHP at all, and to fix that you need increase amount PHP child processes, which I do not want to do.