In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the php method implementation time is too long how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Solve the problem that the execution time of PHP method is too long to cause 502Bad Gateway.
Background
A recent problem is that there is a piece of PHP code that involves a long IO operation, which blocks the thread on which the request resides, causing the request to time out.
You might say, "what's so hard about this? open a thread to do it asynchronously, and OK it when you're done updating the status." This is really a good plan, but unfortunately this whole set of code belongs to someone else. If you want to change the code, the business will affect the whole body, so my solution is to try not to modify the code, by configuring the timeout to solve this problem.
Solution
Judging from the above problems, timeouts are mainly affected by two factors:
Nginx gateway request timeout setting
PHP script execution time limit setting
Let's set it up in turn.
Nginx gateway request timeout setting
Nginx supports timeout settings with fine granularity. The main ones used are as follows:
Keepalive_timeout
Nginx uses keepalive_timeout to specify the timeout for KeepAlive. Specifies how long each TCP connection can be maintained. The default value for Nginx is 75 seconds, and some browsers can only hold for up to 60 seconds, so you can set it to 60 seconds.
Fastcgi_connect_timeout
Timeout for establishing a connection to the FastCGI server.
Fastcgi_send_timeout
Sets the timeout for transferring requests to the FastCGI server. The timeout is set only between two consecutive write operations, not for the transfer of the entire request. If the FastCGI server does not receive anything within this time, close the connection.
Fastcgi_read_timeout
Timeout for reading the response from the FastCGI server. The timeout is set only between two consecutive read operations, not for the transmission of the entire response. If the FastCGI server does not transmit anything within this time, close the connection.
Consider that the execution of a request PHP script is related to the last three settings. So just add the settings in the Nginx configuration file of the corresponding website.
Fastcgi_connect_timeout 600s, fastcgiveness, endurance timeout, 600s, fastcgiveness, readability timeout 600s
PHP script execution time limit setting
The execution time of PHP scripts is mainly affected by two configurations:
Max_execution_time and max_input_time in php.ini
The default location of php.ini is / usr/local/php/etc/
Modify these two configuration items in the php.ini configuration file to the timeout limit.
Max_execution_time = 600max_input_time = 600,
Request_terminate_timeout in php-fpm.conf
The default location of php-fpm.conf is / usr/local/php/etc/
Request_terminate_timeout is also set to the upper limit of the timeout.
Request_terminate_timeout = 600,
Restart Nginx and php-fpm after modification.
Service nginx reload/etc/init.d/php-fpm reload thank you for reading this article carefully. I hope the article "what if the php method takes too long to execute" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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
© 2024 shulou.com SLNews company. All rights reserved.