Answer the question
In order to leave comments, you need to log in
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.php
fulfills.
The forum works fine except for this script.
Piece of nginx config:
location ~ \.php$ {
...
fastcgi_read_timeout 600;
...
}
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"
Answer the question
In order to leave comments, you need to log in
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
Where did you get phpinfo? in php5-fpm or in cli? I suspect that
php scriptname.phpworks fine, then you got the value from cli .
request_terminate_timeout = 300
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();
}
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 questionAsk a Question
731 491 924 answers to any question