Remember a nginx504GatewayTime-out, nginxtime-out. Remember a nginx504GatewayTime-out, nginxtime-out today, the program in the execution of an excel export task appeared nginx timeout prompt nginx504GatewayTime-out troubleshooting process: check a nginx 504 Gateway Time-out, nginxtime-out
Today, the program prompts nginx timeout when executing an excel export task.
Ngnix 504 Gateway Time-out
Troubleshooting process:
Check the task and find that the content is a data volume of 20000 pieces of information. each piece of information has 50 fields. this problem occurs when exporting to excel.
Execution times out in about 10 minutes.
Analysis:
The meaning of Nginx 504 Gateway Time-out is that the requested Gateway does not request to, simply put, there is no request to the PHP-CGI that can be executed
This problem is usually caused by the following situations:
1. The program is processing a large amount of data, or has an endless loop or other problems.
2. a connection such as creating a database cannot be connected for some reason, and there is no timeout and failure mechanism. as a result, the connection is still being created.
3. there are some http requests in the program. these requests are executed for a long time, resulting in timeout.
View nginx and php configurations, and view specific timeout parameters.
Find the nginx configuration file
# Modify Nginx configuration: fastcgi_connect_timeout 1200 s; # originally set to 300sfastcgi_send_timeout 1200 s; # originally set to 300sfastcgi_read_timeout 1200 s; # originally set to listen 64 k; fastcgi_buffers 4 64 k; fastcgi_busy_buffers_size 128 k; fastcgi_temp_file_write_size 256 k;
The most important setting here is the first three, that is
Fastcgi_connect_timeout # Same as the connection timeout time of the FastCGI server. the default value is 60 seconds. it cannot exceed 75 seconds;
Fastcgi_send_timeout # the request sent by the Nginx process to the FastCGI process. The timeout value of the entire process is 60 seconds by default;
Fastcgi_read_timeout # The response sent by the FastCGI process to the Nginx process. The timeout value of the entire process is 60 seconds by default;
Php configuration file
Php. ini
Max_execution_time = 300 s; maximum execution time of PHP scripts. However, this parameter does not take effect in php-cgi (php-fpm.
Php-fpm
Request_terminate_timeout = 0; # set the time-out stop time for a single request. if it is set to 0, the execution continues until the end of the program does not time out.
After the preceding settings are modified, the 504 timeout prompt is not displayed, but the page is blank and no files are exported. It should still be php timeout during execution
The php code cannot be viewed and the execution time is not set: set_time_limit
Baidu's php function execution time found the following content:
Set_time_limit
This function is used to configure the longest execution time of the page. The default value is 30 seconds. in php. ini, the max_execution_time variable is configured. if it is set to 0, the maximum time is not limited.
Computing starts only when the function is executed. For example, if the default value is 30 seconds, and 25 seconds have been executed before the function is executed, and the function is changed to 20 seconds, the maximum execution time of the page is 45 seconds.
Finally, the following line is added to the php function:
Set_time_limit (0 );
Run the command again and the result is OK.
Nginx 504 Gateway Time-out, nginxtime-out today, when the program executes an excel export task, the nginx timeout prompt appears: nginx 504 Gateway Time-out troubleshooting process: check...