最近從GOOGLE ananlytics 發現網站速度變慢了很多,於是想到了PHP中的FPM慢日志功能。
好在 PHP-FPM 提供了慢執行日志,可以將執行比較慢的腳本的調用過程 dump 到日志中。
Shell代碼
cd /etc/php5/fpm/pool.d/
vi www.conf
修改配置
Java代碼
; 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
加上慢執行日志後,我們可以很容易從慢執行日志中看出問題所在,比如:
Log代碼
[13-May-2013 05:17:12] [pool www] pid 13557 script_filename = /opt/www/inkebook/index.php [0x000000000292e0f0] commit() /opt/www/inkebook/includes/database/mysql/database.inc:166 [0x000000000292de88] popCommittableTransactions() /opt/www/inkebook/includes/database/database.inc:1128 [0x000000000292dcf0] popTransaction() /opt/www/inkebook/includes/database/database.inc:1905 [0x00007fffe78cc460] __destruct() unknown:0 [0x000000000292c690] execute() /opt/www/inkebook/modules/statistics/statistics.module:73 [0x00007fffe78cc900] statistics_exit() unknown:0 [0x000000000292c208] call_user_func_array() /opt/www/inkebook/includes/module.inc:857 [0x000000000292bf10] module_invoke_all() /opt/www/inkebook/includes/common.inc:2688 [0x000000000292ade0] drupal_page_footer() /opt/www/inkebook/includes/common.inc:2676 [0x000000000292aa28] drupal_deliver_html_page() /opt/www/inkebook/includes/common.inc:2560 [0x000000000292a378] drupal_deliver_page() /opt/www/inkebook/includes/menu.inc:532 [0x000000000292a198] menu_execute_active_handler() /opt/www/inkebook/index.php:21
再進行進一步的程序分析,就更具方向性了。
查看本欄目