Z
Z
zveb2014-11-24 22:10:09
PHP
zveb, 2014-11-24 22:10:09

Long script on Nginx, php5-fpm. Error 504 after 60 sec. Where to look?

There is a long-playing php script - it works for about 3 minutes.
Through php scriptname.phpfulfills.
The forum works fine except for this script.
Piece of nginx config:

location ~ \.php$ {
                ...
                fastcgi_read_timeout 600;
                ...
        }

The browser, when accessing the script, issues in a minute: "504 Gateway Time-out"
in the ngnix log:
2014/11/23 05:21:05 [error] 8534#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.41, server: server.ru, request: "GET /scriptname.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock", host: "server.ru"

phpinfo() states that max_execution_time = 0
Who else can limit script execution time? Where to dig?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
neolink, 2014-11-25
@zveb

well, if you get a response with 504, then you need to tune nginx , you
may also have to raise keepalive_timeout
, but in general, transfer the execution of this script to cron

B
Boris Benkovsky, 2014-11-24
@benbor

Where did you get phpinfo? in php5-fpm or in cli? I suspect that

php scriptname.php
works fine, then you got the value from cli .
1. Look for the config in /etc/php5/fpm/php.ini
2. Either our favorite custom code
(if this directive can be changed at runtime .... I just don’t remember)
There is also a variable for the php5fpm pool (I don’t remember exactly the file , like this /etc/php5/fpm/pool.d/your_pool)
request_terminate_timeout = 300

A
Alexey Sundukov, 2014-11-24
@alekciy

The maximum time that nginx waits for a response from the backend is 75 seconds. Moreover, this is hardcoded in the code of nginx itself. This is the limit value of the fastcgi_read_timeout config directive (which is just 60 seconds by default). Longer time needed - flush buffers on the backend at least this time. I so desire:

// отправляем данные nginx-у что бы не выйти за fastcgi_read_timeout
$output_buffer = ob_get_length();
if ( !empty($output_buffer) ) {
    flush();
    ob_flush();
}

V
VovanZ, 2014-11-24
@VovanZ

If you need the script to just work, and you do not need to get the result in the browser, then you can set ignore_user_abort(true) ( ​​php.net/manual/ru/function.ignore-user-abort.php) so that the script is finalized after how nginx stops waiting for a response, or interrupt the waiting itself, using fastcgi_finish_request() ( php.net/manual/en/function.fastcgi-finish-request.php) and then finish everything that needs to be done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question