PHP慢日子查詢
2開啟慢日誌
配置輸出php-fpm慢日誌,閥值為2秒:
request_slowlog_timeout = 2
slowlog = log/$pool.log.slow
利用sort/uniq命令分析匯總php-fpm慢日誌:
[[email protected] log]# grep -v "^$" www.log.slow.tmp | cut -d " " -f 3,2 | sort | uniq -c | sort -k1,1nr | head -n 50
5181 run() /www/test.net/framework/web/filters/CFilter.php:41
5156 filter() /www/test.net/framework/web/filters/CFilterChain.php:131
2670 = /www/test.net/index.php
2636 run() /www/test.net/application/controllers/survey/index.php:665
2630 action() /www/test.net/application/controllers/survey/index.php:18
2625 run() /www/test.net/framework/web/actions/CAction.php:75
2605 runWithParams() /www/test.net/framework/web/CController.php:309
2604 runAction() /www/test.net/framework/web/filters/CFilterChain.php:134
2538 run() /www/test.net/framework/web/CController.php:292
2484 runActionWithFilters() /www/test.net/framework/web/CController.php:266
2251 run() /www/test.net/framework/web/CWebApplication.php:276
1799 translate() /www/test.net/application/libraries/Limesurvey_lang.php:118
1786 load_tables() /www/test.net/application/third_party/php-gettext/gettext.php:254
1447 runController() /www/test.net/framework/web/CWebApplication.php:135
參數解釋:
sort: 對單詞進行排序
uniq -c: 顯示唯一的行,並在每行行首加上本行在文件中出現的次數
sort -k1,1nr: 按照第一個字段,數值排序,且為逆序
head -10: 取前10行數據
PHP慢日子查詢