善用php-fpm的慢执行日志slow log分析PHP执行效率和程序BUG
2015-11-29 22:13
701 查看
启用 php-fpm 的 slow log 日志,查看执行时间过长的php文件,并将执行时间过长的进程直接终止掉!看看效果如何!
具体操作方法也简单,就修改一个文件,执行命令:# vi /usr/local/php/etc/php-fpm.conf
PHP 5.3.3 之前版本设置如下:
PHP 5.3.3 之后版本设置如下:
注:request_terminate_timeout 将执行时间太长的进程直接终止
request_slowlog_timeout 将执行过慢的文件写入日志
以后即可根据慢执行日志 /usr/local/php/var/log/slow.log 来优化程序文件了!
具体操作方法也简单,就修改一个文件,执行命令:# vi /usr/local/php/etc/php-fpm.conf
PHP 5.3.3 之前版本设置如下:
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' <value name="request_terminate_timeout">10s</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">1s</value> The log file for slow requests <value name="slowlog">logs/slow.log</value>
PHP 5.3.3 之后版本设置如下:
; 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 = 1s (对执行时间超过1s的php脚本进行日志记录) ; The log file for slow requests ; Default Value: /usr/local/php/var/log/php-fpm.log.slow slowlog = /usr/local/php/var/log/php-fpm.log.slow (开启慢执行日志,日志目录路径一定要正确存在,否则会报错) ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 30s (当php脚本执行时间超过30秒后终止该php脚本)
注:request_terminate_timeout 将执行时间太长的进程直接终止
request_slowlog_timeout 将执行过慢的文件写入日志
以后即可根据慢执行日志 /usr/local/php/var/log/slow.log 来优化程序文件了!
相关文章推荐
- PHP缓存技术的使用说明
- Zend Studio添加行注释和设置模板
- php缓存技术详细介绍及php缓存的实现代码
- 几款常用PHP开发工具
- thinkphp笔记-常量参考
- php+mysql
- ThinkPHP框架二 框架配置
- PHP_XmlRpc简单实现;
- PHP-校花评选-埃洛等级分系统(Elo rating system)
- 10行代码搞定PHP页面静态化(10 lines of code to get PHP static pages)
- thinkphp笔记-读取数据
- 自动加载类PHP中spl_autoload_register函数的用法
- ThinkPHP框架一 框架搭建
- netstat -altp
- Ubuntu14.04 vsftpd安装与配置
- How to execute tons of tasks parallelly with TPL method?
- PHP不使用递归的无限级分类
- 简单配置局域网FTP
- 在eclipse中用thinkphph框架
- PHP 验证日期格式