PHP Time-out processing comprehensive summary (1) _php tutorial

Source: Internet
Author: User
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:

 
  
  
  1. < Span class= "Tag-name" >ifmodule mod_fastcgi.c >
  2. fastcgiexternalserver/home/forum/apache/apache_php/cgi-bin/php-cgi-socket/home/forum/ Php5/etc/php-fpm.sock
  3. scriptalias/fcgi-bin//home/fo rum/apache/apache_php/cgi-bin/"
  4. AddHandler php-fastcgi . PHP
  5. Action php-fastcgi/fcgi-bin/php-cgi
  6. addtype application/x-httpd-php. php
  7. !-- 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):

 
 
    1. < ifmodule mod_fastcgi.c >
    2. fastcgiexternalserver/home/forum/apache/a Pache_php/cgi-bin/php-cgi-socket/home/forum/php5/etc/php-fpm.sock-idle-timeout
    3. scriptalias/fcgi-bin/"/home/forum/apache/apache_php/cgi-bin/"
    4. AddHandler php-fastcgi. php
    5. Action php-fastcgi/fcgi-bin/php-cgi
    6. Addtyp E application/x-httpd-php. php
    7. !-- ifmodule >

If the timeout returns a 500 error, disconnect the back-end PHP service and log an Apache error logs:

 
  
  
  1. [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:

 
  
  
  1. IdleTimeout Daze time limit
  2. Processlifetime the longest life cycle of a process, and unconditionally kill after expiration
  3. Maxprocesscount Maximum number of processes
  4. Defaultminclassprocesscount the minimum number of processes started per program
  5. Defaultmaxclassprocesscount the maximum number of processes started per program
  6. Ipcconnecttimeout Program Response Time-out
  7. 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:

 
  
  
  1. Server.max-keep-alive-idle5
  2. Server.max-read-idle
  3. Server.read-timeout0
  4. Server.max-connection-idle
 
 
  1. --------------------------------------------------
  2. # The maximum number of requests per keep-alive, the default value is 16
  3. server.max-keep-alive-requests = -
  4. # keep-alive The maximum wait time, in seconds, the default value is 5
  5. Server.max-keep-alive-idle = -
  6. # Lighttpd of work subprocess, default value is 0, single process run
  7. Server.max-worker = 2
  8. # Limit the user's maximum intermediate pause time (in seconds) during the sending of a request
  9. # 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
  10. # Default value is 60 (seconds)
  11. Server.max-read-idle = -
  12. # Limit the maximum intermediate pause time (in seconds) for a user to receive an answer.
  13. # If the user is in the process of receiving the answer (not finished), the middle pause time is too long, LIGHTTPD will actively disconnect
  14. # Default value is 360 (seconds)
  15. Server.max-write-idle = 12000
  16. # The timeout limit for read client requests, in seconds, with 0 for no limit
  17. # When set less than Max-read-idle, Read-timeout takes effect
  18. Server.read-timeout = 0
  19. # Write the answer page to the client's timeout limit, in seconds, with 0 for no limit
  20. # When set less than Max-write-idle, Write-timeout takes effect
  21. Server.write-timeout = 0
  22. # 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
  23. Server.max-connection-idle = -
  24. --------------------------------------------------

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

 
 
  1. HTTP {
  2. #Fastcgi: (Fastcgi does not belong to proxy mode for Fastcgi of backend)
  3. Fastcgi_connect_timeout 5; #连接超时
  4. Fastcgi_send_timeout 10; #写超时
  5. Fastcgi_read_timeout 10; #读取超时
  6. #Proxy: (In effect for proxy/upstreams)
  7. Proxy_connect_timeout 15s; #连接超时
  8. Proxy_read_timeout 24s; #读超时
  9. Proxy_send_timeout 10s; #写超时
  10. }

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 ...

  • 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.