动态php 函数追踪,php 函数追踪扩展 phptrace

php 函数追踪扩展 phptrace

介绍

phptrace 是一个低开销的用于跟踪、分析 php 运行情况的工具。

它可以跟踪 php 在运行时的函数调用、请求信息、执行流程、并且提供有过滤器、统计信息、当前状态等实用功能。

在任何环境下,它都能很好的定位阻塞的问题以及在高负载下进行 denbug。

官方源码:https://github.com/Qihoo360/phptrace。

安装

pecl 方式安装

$ pecl install trace

源码方式安装

$ wget https://pecl.php.net/get/trace-1.0.0.tgz # 下载源码

$ tar -xf trace-1.0.0.tgz # 解压文件

$ cd trace-1.0.0/extension # 进入扩展目录

源码编译

$ whereis php-config # 找到 php-config 的路径

$ phpize

$ ./configure --with-php-config=/usr/bin/php-config # 这里的 --with-php-config 是上一步找到的路径

$ make # 编辑

$ make test # 编译测试

$ make cli # 命令行工具

$ make install-all # 安装 php 扩展,命令行工具到 php 目录

修改 php.ini

在 php.ini 配置文件中增加以下配置信息。

[phptrace]

extension=trace.so

phptrace.enabled=1

注:修改 php.ini 后,需要手动重启 php-fpm

检查是否生效

root@639ca1f15214:~# php -m | grep trace

trace

实际测试

root@639ca1f15214:/var/www# php -r 'for ($i = 0; $i < 20; $i++) { sleep(5); }' &

[1] 361

root@639ca1f15214:/var/www# phptrace -p $!

process attached

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.966s 4.966s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.002s 5.002s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.002s 5.002s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.966s 4.966s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.003s 5.003s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s

[pid 361] > sleep(5) called at [Command line code:1]

[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.967s 4.967s

[pid 361]> swoole_call_user_shutdown_begin() called at [(null):0]

[pid 361]< swoole_call_user_shutdown_begin() = true called at [(null):0] ~ 0.000s -79.912s

[pid 361]< cli php for ($i = 0; $i < 20; $i++) { sleep(5); }

process detached

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值