Overview
In the PHP development work very much uses the time-out processing to the time-out situation, I say several scenes:
1. Get data asynchronously if a backend data source gets unsuccessful then skips without affecting the entire page presentation
2. To ensure that the Web server does not have access to other pages due to poor performance of the page processing, some page operations are set
3. For some upload or uncertain processing time, you need to set the entire process to unlimited time, or any one of the links set incorrectly, will lead to inexplicable execution interruption
4. Multiple back-end modules (MySQL, Memcached, HTTP interface), in order to prevent poor performance of a single interface, resulting in the entire front to get data too slow, affecting the page opening speed, causing avalanche
5 ..... Lots of occasions that need to be timed out
These places need to consider the setting of timeouts, but the time-out in PHP is categorized, each processing method and strategy are different, in order to describe the system, I summed up the common PHP time-out processing summary.
"Web Server timeout Processing"
[Apache]
Generally in high performance situations, the default all timeout configuration is 30 seconds, but in the case of uploading files, or network speed is very slow, it is possible to trigger a timeout operation.
There are currently three timeout settings in Apache fastcgi php-fpm mode:
FastCGI Timeout setting:
Modify the httpd.conf fastcgi connection configuration, similar to the following:
- < Span class= "Tag-name" >ifmodule mod_fastcgi.c >
- fastcgiexternalserver/home/forum/apache/apache_php/cgi-bin/php-cgi-socket/home/forum/ Php5/etc/php-fpm.sock
-
- scriptalias/fcgi-bin//home/fo rum/apache/apache_php/cgi-bin/"
-
- AddHandler php-fastcgi . PHP
-
- Action php-fastcgi/fcgi-bin/php-cgi
-
- addtype application/x-httpd-php. php
-
- !-- ifmodule >
The
Default configuration is 30s, if you need to customize your configuration, you need to modify the configuration, such as modified to 100 seconds: (restart Apache after modification):
- < ifmodule mod_fastcgi.c >
-
- fastcgiexternalserver/home/forum/apache/a Pache_php/cgi-bin/php-cgi-socket/home/forum/php5/etc/php-fpm.sock-idle-timeout
-
- scriptalias/fcgi-bin/"/home/forum/apache/apache_php/cgi-bin/"
-
- AddHandler php-fastcgi. php
-
- Action php-fastcgi/fcgi-bin/php-cgi
-
- Addtyp E application/x-httpd-php. php
-
- !-- ifmodule >
If the timeout returns a 500 error, disconnect the back-end PHP service and log an Apache error logs:
- [Thu Jan 27 18:30:15 2011] [ERROR] [Client 10.81.41.110] Fastcgi:comm with Server "/home/forum/apache/apache_php/cgi-bin/php-cgi" Aborted:idle timeout (sec)
Additional fastcgi configuration parameter description:
- IdleTimeout Daze time limit
- Processlifetime the longest life cycle of a process, and unconditionally kill after expiration
- Maxprocesscount Maximum number of processes
- Defaultminclassprocesscount the minimum number of processes started per program
- Defaultmaxclassprocesscount the maximum number of processes started per program
- Ipcconnecttimeout Program Response Time-out
- Ipccommtimeout the maximum time to communicate with the program, the above error may be caused by this value set too small
[LIGHTTPD]
Configuration: lighttpd.conf
In the LIGHTTPD configuration, there are several parameters about timeouts (space considerations, write-only timeouts, and write timeout parameters):
The main concerns are options:
- Server.max-keep-alive-idle5
- Server.max-read-idle
- Server.read-timeout0
- Server.max-connection-idle
- --------------------------------------------------
- # The maximum number of requests per keep-alive, the default value is 16
- server.max-keep-alive-requests = -
- # keep-alive The maximum wait time, in seconds, the default value is 5
- Server.max-keep-alive-idle = -
- # Lighttpd of work subprocess, default value is 0, single process run
- Server.max-worker = 2
- # Limit the user's maximum intermediate pause time (in seconds) during the sending of a request
- # If the user is in the process of sending the request (not completing the request), the middle pause time is too long, LIGHTTPD will actively disconnect
- # Default value is 60 (seconds)
- Server.max-read-idle = -
- # Limit the maximum intermediate pause time (in seconds) for a user to receive an answer.
- # If the user is in the process of receiving the answer (not finished), the middle pause time is too long, LIGHTTPD will actively disconnect
- # Default value is 360 (seconds)
- Server.max-write-idle = 12000
- # The timeout limit for read client requests, in seconds, with 0 for no limit
- # When set less than Max-read-idle, Read-timeout takes effect
- Server.read-timeout = 0
- # Write the answer page to the client's timeout limit, in seconds, with 0 for no limit
- # When set less than Max-write-idle, Write-timeout takes effect
- Server.write-timeout = 0
- # The processing time limit of the request, if used Mod_proxy_core, that is, and the back end of the interaction time limit, the unit is the second
- Server.max-connection-idle = -
- --------------------------------------------------
Description
For successive requests on a keep-alive connection, the maximum interval for sending the content of the first request is determined by the parameter max-read-idle, and the maximum interval for sending the requested content from the second request 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 interaction data with the backend is determined by Max-connection-idle.
Extended reading:
http://www.snooda.com/read/244
[Nginx]
Configuration: nginx.conf
- HTTP {
- #Fastcgi: (Fastcgi does not belong to proxy mode for Fastcgi of backend)
- Fastcgi_connect_timeout 5; #连接超时
- Fastcgi_send_timeout 10; #写超时
- Fastcgi_read_timeout 10; #读取超时
-
- #Proxy: (In effect for proxy/upstreams)
- Proxy_connect_timeout 15s; #连接超时
- Proxy_read_timeout 24s; #读超时
- Proxy_send_timeout 10s; #写超时
- }
Description
Nginx timeout settings are very clear and easy to understand, the above time-out for different modes of operation, but because the time-out caused by a lot of problems.
Extended reading:
Http://hi.baidu.com/pibuchou/blog/item/a1e330dd71fb8a5995ee3753.html
Http://hi.baidu.com/pibuchou/blog/item/7cbccff0a3b77dc60b46e024.html
Http://hi.baidu.com/pibuchou/blog/item/10a549818f7e4c9df703a626.html
http://www.apoyl.com/?p=466
1
http://www.bkjia.com/PHPjc/445662.html www.bkjia.com true http://www.bkjia.com/PHPjc/445662.html techarticle "Overview" in the PHP development work very much use to time-out processing to time-out, I say a few scenarios: 1. Asynchronously gets data if a backend data source gets unsuccessful then skips ...