In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Nginx and FastCGI which affect timeout". In daily operation, I believe many people have doubts about which influence timeout between Nginx and FastCGI. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "which influence timeout between Nginx and FastCGI". Next, please follow the editor to study!
Demand:
A php program takes some time to run, but the time is uncertain.
Question:
The php program is forced to disconnect when it has been running for more than a period of time.
PHP itself timeout processing
In php.ini, there is a parameter, max_execution_time, that sets the maximum execution time of the PHP script, but in php-cgi (php-fpm), this parameter has no effect. When you can really control the maximum execution of PHP scripts:
0s
That is to say, it works if you run max_execution_time in mod_php5.so mode, but not if you run in php-fpm mode.
Max_execution_time
Only the execution time of the PHP script itself is calculated, and the time outside the execution is not counted. Which are outside the implementation of the time? Includes sleep, data interaction, socket interaction, and so on.
Request_terminate_timeout = 0 means it is not controlled by time and never times out.
Resource problems caused by request_terminate_timeout
If the value of request_terminate_timeout is set to 0 or for too long, it may cause resource problems for file_get_contents.
If the remote resource requested by file_get_contents is too slow, the file_get_contents will stay stuck there and will not time out. We know that max_execution_time in php.ini can set the maximum execution time of PHP scripts, but in php-cgi (php-fpm), this parameter does not work. What really controls the maximum execution time of the PHP script is the request_terminate_timeout parameter in the php-fpm.conf configuration file.
The default value for request_terminate_timeout is 0 seconds, which means that the PHP script will be executed forever. In this way, when all php-cgi processes are stuck in the file_get_contents () function, the WebServer of this Nginx+PHP can no longer handle new PHP requests, and Nginx will return "502 Bad Gateway" to the user. It is necessary to modify this parameter to set the maximum execution time of a PHP script, but it does not cure the symptoms. For example, if it is changed to 30s, if file_get_contents () is slow to get web content, this means that there are 150 php-cgi processes that can only process 5 requests per second, and it is also difficult for WebServer to avoid "502 Bad Gateway". The solution is to set request_terminate_timeout to 10s or a reasonable value, or add a timeout parameter to file_get_contents
If there is a frequent request timeout, open the slow log of php-fpm to confirm the evaluation timeout.
Fastcgi request time Control in Ngnix
Fastcgi_connect_timeout
Syntax: fastcgi_connect_timeout time
Default value: fastcgi_connect_timeout 60
Use fields: http, server, location
Specifies the connection timeout to the FastCGI server, which cannot exceed 75 seconds.
Fastcgi_read_timeout
Syntax: fastcgi_read_timeout time
Default value: fastcgi_read_timeout 60
Use fields: http, server, location
The response timeout of the front-end FastCGI server, which may need to be adjusted if there are some long-running FastCGI processes that do not have output until they are finished, or if the front-end server response timeout error occurs in the error log.
Fastcgi_send_timeout
Syntax: fastcgi_send_timeout time
Default value: fastcgi_send_timeout 60
Use fields: http, server, location
The instruction sets the data transfer time for the upstream server to wait for a FastCGI process. If there are some long-running FastCGI processes that do not have output until they are finished, you can modify this value, and if you find some timeout errors in the error log of the upstream server, you can increase this value appropriately.
The instruction specifies the timeout of the request server, which means that the connection with the 2-way handshake is completed instead of the full connection, and if the client does not transfer data during this period, the server will close the connection.
In the Nginx+FastCGI configuration test
When request_terminate_timeout is set to never time out, the setting time of fastcgi_read_timeout in nginx will affect the final timeout.
During the test, if it is a timeout in php-fpm
502 Bad Gateway will be displayed
502 Bad Gateway502 Bad Gatewaynginx
If the cgi configuration in nginx timed out
504 Gateway Time-out will be displayed
At this point, the study of "which affects the timeout between Nginx and FastCGI" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un