PHP日志
2020-01-03 本文已影响0人
六弦极品
一、php-fpm 慢日志
php慢日志需要在php-fpm.conf设置,旧的版本是在php-fpm.conf设置,php7.x版本源码包编译后需要www.conf修改慢查询配置,如果在php-fpm.conf找不到,就去同级目录php-fpm.d下面找下。
# vim /usr/local/php/etc/php-fpm.d/www.conf
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0
例子:
request_slowlog_timeout = 5s
slowlog = /usr/local/php/var/log/php-fpm-slowlog.log
request_terminate_timeout = 10s
说明:
slowlog 设置慢查询日志的生成目录
request_slowlog_timeout 设置慢查询的标准时间(打开此配置就相当于开启了慢查询日志),配置以秒为单位,一般设置3s。
request_terminate_timeout 将执行时间太长的进程直接终止;
二、php-error 错误日志
一般情况下,php错误日志的配置都在php.ini文件中
# vim /usr/local/php/etc/php.ini
---------------------------
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
log_errors = On
; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog
error_log 错误日志的生成目录
error_reporting 生产环境错误级别应全开
display_errors 在页面上不显示错误
log_errors 开启错误日志
最终的结果:
error_log = /var/log/php_error.log
display_errors = Off
error_reporting = E_ALL
log_errors = On