本文实例讲述了php程序员必须知道的两种日志。分享给大家供大家参考,具体如下:
作为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询。下面列出常见日志及设置方法。
php慢日志需要在php-fpm.conf设置,如果使用源码包安装默认请执行下面命令
cp php-fpm.conf.default php-fpm.conf
默认通过源码包编译安装php目录应在
/usr/local/php
目录下,如果你通过yum或者其他方式安装,不清楚或不知道php具体安装目录,可以使用
find / -name php-fpm.conf
or
php -i | grep path ------------------------------------------ [root@xxxx etc]# php -i | grep path configuration file (php.ini) path => /usr/local/php/etc xpath support => enabled path to sendmail => /usr/sbin/sendmail -t -i [root@xxxx etc]#
旧的版本是在php-fpm.conf设置 (实际是我忘记了哪个版本),php7.x版本源码包编译后需要www.conf修改慢查询配置
vim /usr/local/php/etc/php-fpm.d/www.conf
不过配置项都一样的,如果你在php-fpm.conf找不到,就去他的同级目录php-fpm.d下面找下吧。
; 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
在生产环境中是不允许php报错的,就算报错也是白屏或者500,所以在生产环境中的日志收集是非常重要的。
一般情况下,php错误日志的配置都在php.ini文件中
/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 = /var/log/php_error.log display_errors = off error_reporting = e_all log_errors = on
如对本文有疑问, 点击进行留言回复!!
如何去设计前端框架能力?星巴克消息开放项目从0到1,从点到面的思考
PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分
网友评论