PHP本身超时处理】
[ PHP-fpm ]
配置:php-fpm.conf
- <?xml version="1.0" ?>
- <configuration>
- //...
- Sets the limit on the number of simultaneous requests that will be served.
- Equivalent to Apache MaxClients directive.
- Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
- Used with any pm_style.
- #php-cgi的进程数量
- <value name="max_children">128</value>
- The timeout (in seconds) for serving a single request after which the worker process will be terminated
- Should be used when 'max_execution_time' ini option does not stop script execution for some reason
- '0s' means 'off'
- #php-fpm 请求执行超时时间,0s为永不超时,否则设置一个 Ns 为超时的秒数
- <value name="request_terminate_timeout">0s</value>
- The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
- '0s' means 'off'
- <value name="request_slowlog_timeout">0s</value>
- </configuration>
说明:
在 php.ini 中,有一个参数 max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时:
- <value name="request_terminate_timeout">0s</value>
就是说如果是使用 mod_php5.so 的模式运行 max_execution_time 是会生效的,但是如果是php-fpm模式中运行时不生效的。
延伸阅读:
http://blog.s135.com/file_get_contents/
[ PHP ]
配置:php.ini
选项:
- max_execution_time = 30
或者在代码里设置:
- ini_set("max_execution_time", 30);
- set_time_limit(30);
说明:
对当前会话生效,比如设置0一直不超时,但是如果php的 safe_mode 打开了,这些设置都会不生效。
效果一样,但是具体内容需要参考php-fpm部分内容,如果php-fpm中设置了 request_terminate_timeout 的话,那么 max_execution_time 就不生效。
PHP之友评论