Solution to nginx timeout problem in php environment

1. Problem analysis
504 Gateway Time-out occurs during nginx access. Generally, the response timeout is caused by too long program execution time. For example, the program execution takes 90 seconds, and the maximum response waiting time of nginx is 30 seconds, which will cause a timeout.
There are usually the following situations:
(1). The program is processing a large amount of data, causing the waiting timeout.
(2). The external request is called in the program, and the external request response timeout.
(3). The connection to the database fails without stopping, and the connection is reconnected in an endless loop.
When this happens, we can optimize the program first to shorten the execution time. On the other hand, you can adjust the parameters of the nginx timeout limit so that the program can execute normally.
Regarding the access timeout settings, both nginx and php have related settings, which can be modified one by one.
2. Solution In the
nginx configuration
nginx.conf, set the following parameters to increase the timeout time
fastcgi_connect_timeout
fastcgi connection timeout, the default is 60 seconds
fastcgi_send_timeout
nginx process sends the request process to the fastcgi process timeout, the default value is 60 seconds
fastcgi_read_timeout
fastcgi process to The timeout period of the nginx process sending output process, the default value is 60 seconds

php configuration
php.ini
max_execution_time
php script maximum execution time
php-fpm
request_terminate_timeout
Set the timeout time of a single request
php program can add set_time_limit(seconds) to set the longest execution time,
for example set_time_limit(0) means no timeout.

Guess you like

Origin blog.51cto.com/jack88/2551551