测试环境下的php.ini中的错误日志设置:
error_reporting = E_ALL
display_errors = On
html_errors = On
log_errors = Off
正式环境下的php.ini中的错误日志设置:
error_reporting = E_ALL &~ E_NOTICE &~ E_WARNING //注意这个设置,记得有一次因为这个设置有误,导致了线上一个业务访问出现了nginx 500报错!这个导致了php框架报错!
display_errors = Off
log_errors = On
html_errors = Off
error_log = /Data/logs/php/error.log
ignore_repeated_errors = On
ignore_repeated_source = On
简单讲解下各个配置的意义:
error_reporting :设置报告哪些错误
display_errors :设置错误是否作为输出的一部分显示
html_errors :设置错误信息是否采用html格式
log_errors :设置是否记录错误信息
error_log :设置错误信息记录的文件
ignore_repeated_errors :是否在同一行中重复显示一样的错误信息
ignore_repeated_source : 是否重复显示来自同个文件同行代码的错误
顺便记录下php的页面老是报时区错误的处理过程:
Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are
*required* to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier. We selected the
timezone 'UTC' for now, but please set date.timezone to select your timezone. in
/usr/local/www/zabbix2/phpinfo.php on line 2
date/time support enabled
"Olson" Timezone Database Version 2013.8
Timezone Database internal
Default timezone UTC
修改php.ini 文件
# vim /usr/local/php/etc/php.ini
........
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai
查看错误日志发现问题:
[root@i-v5lmgh7y log]# tail -f php-fpm.log
[15-Nov-2015 23:53:15] NOTICE: fpm is running, pid 18277
[15-Nov-2015 23:53:15] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[15-Nov-2015 23:53:16] NOTICE: exiting, bye-bye!
[15-Nov-2015 23:53:59] NOTICE: fpm is running, pid 18855
[15-Nov-2015 23:53:59] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[15-Nov-2015 23:54:00] NOTICE: exiting, bye-bye!
request_terminate_timeout默认值为0秒,也就是说,PHP脚本会一直执行下去。这样当所有的php-cgi进程都卡住时,这台Nginx+PHP的WebServer已经无法再处理新的PHP请求了,Nginx 将给用户返回“502 Bad Gateway”。
修改该参数,设置一个PHP脚本最大执行时间是必要的,但是治标不治本。例如改成30s,如果发生访问获取网页内容较慢的情况,这就意味着150个php-cgi进程,每秒钟只能处理5个请求,WebServer同样很难避免”502 Bad Gateway”。