A comprehensive summary of several common timeouts in PHP (i)

Source: Internet
Author: User

In PHP development work is very much used to timeout processing to the occasion, I say a few scenarios: get the data asynchronously if a backend data source gets unsuccessful, it skips and does not affect the entire page presentation in order to ensure that the Web server will not be able to access other pages because of poor performance on the page, Some of the page operation settings for some upload or uncertain processing time, you need to the entire process of the timeout set to infinity, or any one link set improperly, will cause inexplicable execution interrupt multiple back-end modules (MySQL, Memcached, HTTP interface), In order to prevent a single interface performance is too poor, causing the entire front to get data too slow, affecting the page opening speed, causing avalanches ... Lots of situations that need to be timed out

These places need to consider timeout settings, but the PHP timeout is categorized, the various processing methods and strategies are different, in order to describe the system, I summed up the common PHP in the time-out processing summary.

"Web Server timeout Processing"

[Apache]
Typically, in high performance situations, the default timeout configuration is 30 seconds, but when uploading files, or if the network is slow, the timeout operation may be triggered.
There are currently three timeout settings in APACHEFASTCGIPHP-FPM mode:
FastCGI Timeout setting:
Modify the httpd.conf fastcgi connection configuration, similar to the following:

The code is as follows
the maximum number of requests per keep-alive, and the default value is

server.max-keep-alive-requests=100 keep-alive Maximum wait time, in seconds, default value is 5

number of work server.max-keep-alive-idle=1200 lighttpd, default value is 0, single process runs

server.max-worker=2 limits the maximum intermediate pause time (in seconds) for a user to send a request, and if the user is in the process of sending a request (no request has been made), the middle pause is too long and LIGHTTPD will actively disconnect The default value is 60 (seconds)

server.max-read-idle=1200 limits the maximum intermediate pause time (in seconds) for a user to receive an answer, and if the user is in the process of receiving an answer (not finished), the middle pause is too long. LIGHTTPD will actively disconnect The default value is 360 (sec)

server.max-write-idle=12000 Read client request timeout limit, in seconds, with 0 for no limit set less than Max-read-idle, read-timeout effective

Server.read-timeout=0 Write Answer page to the client timeout limit, the unit is seconds, with 0 to indicate that no limit set is less than Max-write-idle, write-timeout effective

server.write-timeout=0 Request Processing time limit, if the mod_proxy_core, that is, and back-end interaction time limit, the unit is seconds

server.max-connection-idle=1200

Description
For a continuous request on a keep-alive connection, the maximum interval for sending the first request content is determined by the parameter max-read-idle, and from the second request the maximum interval for sending the requested content is determined by the parameter max-keep-alive-idle. The interval timeout between requests is also determined by Max-keep-alive-idle. The total time timeout for sending the requested content is determined by the parameter read-timeout. The timeout for lighttpd and back-end interaction data is determined by Max-connection-idle.

[Nginx]
Configuration: nginx.conf

The code is as follows:
http{
#Fastcgi:(Fastcgi for the backend, Fastcgi is not in proxy mode)
FASTCGI_CONNECT_TIMEOUT5; #连接超时
fastcgi_send_timeout10; #写超时
fastcgi_read_timeout10; #读取超时
#Proxy:(in effect for proxy/upstreams)
proxy_connect_timeout15s; #连接超时
proxy_read_timeout24s; #读超时
proxy_send_timeout10s; #写超时
}

Description
The timeout setting for Nginx is very clear and easy to understand, and the above timeout is for different working modes, but the problem with timeouts is very much.

Hope that the above is helpful to you, finally, please help to order a praise thank you ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.