• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

php函数追踪扩展phptrace

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

介绍

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人参与评论

请发表评论

全部评论

专题导读
上一篇:
js、php判断手机PC发布时间:2022-07-10
下一篇:
linux使用crontab实现PHP执行定时任务(转)发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap