用PHP-FPM 的 slow log 分析网站
最近从GOOGLE ananlytics 发现网站速度变慢了很多, 于是想到了PHP中的FPM慢日志功能。好在 PHP-FPM 提供了慢执行日志,可以将执行比较慢的脚本的调用过程 dump 到日志中。
cd /etc/php5/fpm/pool.d/
vi www.conf
修改配置
; 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
; The log file for slow requests
; Default Value: /usr/local/php/log/php-fpm.log.slow
slowlog = /usr/local/php/log/php-fpm.log.slow
加上慢执行日志后,我们可以很容易从慢执行日志中看出问题所在,比如:
pid 13557
script_filename = /opt/www/inkebook/index.php
commit() /opt/www/inkebook/includes/database/mysql/database.inc:166
popCommittableTransactions() /opt/www/inkebook/includes/database/database.inc:1128
popTransaction() /opt/www/inkebook/includes/database/database.inc:1905
__destruct() unknown:0
execute() /opt/www/inkebook/modules/statistics/statistics.module:73
statistics_exit() unknown:0
call_user_func_array() /opt/www/inkebook/includes/module.inc:857
module_invoke_all() /opt/www/inkebook/includes/common.inc:2688
drupal_page_footer() /opt/www/inkebook/includes/common.inc:2676
drupal_deliver_html_page() /opt/www/inkebook/includes/common.inc:2560
drupal_deliver_page() /opt/www/inkebook/includes/menu.inc:532
menu_execute_active_handler() /opt/www/inkebook/index.php:21
再进行进一步的程序分析,就更具方向性了。
欢迎访问下面网站, 下载电子书
http://www.inkebook.com/
页:
[1]