[php fpm]php-fpm的慢执行日志slow log分析

更新时间:2020-11-05    来源:nginx    手机版     字体:

【www.bbyears.com--nginx】

背景:看PHP的慢日志一般来讲主要是看网络接口上的问题,有时间一台服务器会调用api接口,而该接口呢在另一吧机器上,而有人恶意透过这个接口频繁调用,飙高带宽,进而导致一堆TIME_WAIT,nginx出现白页,此时,这是现象,如何由现象看到本质,那就打开php-fpm的slow的日志吧,如何打开,接着向下看吧。


众所周知,mysql有slow query log,根据慢查询日志,我们可以知道那些sql语句有性能问题。作为mysql的好搭档,php也有这样的功能。如果你使用php-fpm来管理php的话,你可以通过如下选项开启。
PHP 5.3.3 之前设置如下:

5s
logs/php-fpm-slowlog.log

说明:

request_slowlog_timeout 是脚本超过多长时间 就可以记录到日志文件
slowlog 是日志文件的路径

开启后,如果有脚本执行超过指定的时间,就会在指定的日志文件中写入类似如下的信息:
request_slowlog_timeout = 0s^M 
slowlog = /data/logs/php/slow.log^M 


[19-Dec-2013 16:54:49] [pool www] pid 18575
script_filename = /home/web/htdocs/sandbox_canglong/test/tt.php
[0x0000000003a00dc8] curl_exec() /home/web/htdocs/sandbox_canglong/test/tt.php:2
[0x0000000003a00cd0] exfilter_curl_get() /home/web/htdocs/sandbox_canglong/test/tt.php:6

日志说明:

script_filename 是入口文件
curl_exec() : 说明是执行这个方法的时候超过执行时间的。
exfilter_curl_get() :说明调用curl_exec()的方法是exfilter_curl_get() 。

每行冒号后面的数字是行号。

开启后,在错误日志文件中也有相关记录。如下:

script_filename = /data/www/justwinit/index.php 
[0x00007ff0f9c9cdc8] curl_exec() /data/www/justwinit/application/class/weibo.class.php:2081 
[0x00007ff0f9c9cc40] oAuthRequesthttp() /data/www/justwinit/application/modules/xweibo/xwb.com.php:767 
[0x00007fffeb65c010] getFsFollowers() unknown:0 
[0x00007ff0f9c9c990] call_user_func_array() /data/www/justwinit/application/core.php:3157 
[0x00007fffeb65c350] call() unknown:0 
[0x00007ff0f9c9c818] call_user_func_array() /data/www/justwinit/application/core.php:3269 
[0x00007ff0f9c9c4c0] DR() /data/www/justwinit/application/controllers/ta.mod.php:375 
[0x00007ff0f9c9c330] default_action() /data/www/justwinit/application/core.php:1819 
[0x00007ff0f9c9c1e8] M() /data/www/justwinit/application/core.php:270 
[0x00007ff0f9c9c0f0] request() /data/www/justwinit/index.php:157 

本文来源:http://www.bbyears.com/caozuoxitong/108925.html