D
D
Dmitry Sonko2013-11-15 21:24:49
PHP
Dmitry Sonko, 2013-11-15 21:24:49

Nginx + PHP-FPM = 504?

Essence of a question, there is an internal service. There are forms, a request is sent from the form to a script on the server. The script takes a long time to run. As a result, a minute after sending, the enginx flies from the 504th. I set all possible timeouts in its config, twisted the execution time of php scripts to the maximum. Please tell me which way to dig, the answer still comes in a minute and exactly 504.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vlad Zhivotnev, 2013-11-15
@SonkoDmitry

If php-fpm over tcp, then:
proxy_read_timeout 180;
proxy_send_timeout 180;
If via socket, then:
fastcgi_read_timeout 180;
fastcgi_send_timeout 180;
Also for both cases.:
client_body_timeout 180;
send_timeout 180;
grep -rni timeout /etc/php5/fpm/ show at the same time.

R
Rail Khamdeev, 2013-11-15
@rhamdeew

Bring php.ini configs and nginx configs.
You can also look at phpinfo () because it happens that there are a lot of configs and it may not be used exactly the one you need. And so you will see if your settings have been applied or not.

A
alex1234, 2013-11-15
@alex1234

what about the script code? In it the maximum time cannot be defined anywhere?

A
Alexey Sundukov, 2013-11-17
@alekciy

@inkvizitor68sl certainly gave the right direction. But I would like to add a few more important points in case it turns out that in the config all timeouts are set as 180 seconds each, and the script still falls off in the region of a minute anyway. Salt next.
If PHP does not return anything until the end of its work, then such a setting as fastcgi_connect_timeout comes into effect. proxy_read_timeout does not work here yet (because in fact the connection is not considered established). Moreover, the maximum fastcgi_connect_timeout value is 75 seconds and this value is hardcoded in nginx itself. Therefore, if the script needs to run longer, then you need to echo something from PHP.

B
Boris Syomov, 2013-11-17
@kotomyava

There is a more correct solution - to execute long processes not in the context of a web server, separating the interface of setting a task and its execution.
For example, set tasks through the web interface, and execute in a script run by cron.
If you need to receive feedback, you can periodically write the execution process to some storage (file, database, key-value), and display it on the client side by making periodic ajax requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question