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

php 函数追踪扩展 phptrace的更多相关文章

  1. ES6 - Note3:数组、对象与函数的扩展

    一.数组的扩展,ES6在数组扩展了一些API,以实现更多的功能 1.Array.from:可以将类数组和可遍历的数据结构转换成真正的数组,如下所示 var a = { '0':1,'1':1,leng ...

  2. ES6入门之函数的扩展

    函数js原有的: 属性:arguments[].caller(调用该函数的引用,注意与callee分别开,callee指的是调用函数本身经常在递归中出现).length(形参个数).prototype ...

  3. 编译器对C++ 11变参模板(Variadic Template)的函数包扩展实现的差异

    编译器对C++ 11变参模板(Variadic Template)的函数包扩展实现的差异 题目挺绕口的.C++ 11的好东西不算太多,但变参模板(Variadic Template)肯定是其中耀眼的一 ...

  4. sqlserver 只有函数和扩展存储过程才能从函数内部执行

    一个SQLServer的自定义函数中调用一个自定义的存储过程,执行此函数后发出如下提示:“只有函数和扩展存储过程才能从函数内部执行". 原因:函数只能使用简单的sql语句,逻辑控制语句,复杂 ...

  5. ES6_入门(6)_函数的扩展

    // 2017/7/22 /*ES6函数的扩展*/ //ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; ...

  6. ES6的新特性(7)——函数的扩展

    函数的扩展 函数参数的默认值 基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console ...

  7. ES6学习(二):函数的扩展

    chapter07 函数的扩展 7.1 函数默认值 7.1.1 参数默认值简介 传统做法的弊端(||):如果传入的参数相等于(==)false的话,仍会被设为默认值,需要多加入一个if判断,比较麻烦. ...

  8. ES6学习笔记(6)----函数的扩展

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 函数的扩展 函数的默认值 : ES6可以为函数指定默认值 (1)指定默认值的两种方式 a.函数参 ...

  9. ES6__函数的扩展

    /** * 函数的扩展 * 1 为函数参数指定默认值 * 2 函数的 rest 参数 * 3 箭头函数 */ // ------------------------------------------ ...

随机推荐

  1. php实现二叉树的遍历

  2. windows下matplotlib的安装

    在上一篇中我想用matplotlib,无奈一直装不上,就在卸了又装装了又卸,反反复复之后,终于装好了. 初学python,首先就装了numpy,倒也没有多复杂,有需要的朋友可以直接http://sou ...

  3. php redis 操作手册

    String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 1 $redis-&g ...

  4. 解决count distinct多个字段的方法

    Distinct的作用是用于从指定集合中消除重复的元组,经常和count搭档工作,语法如下 COUNT( { [ ALL | DISTINCT ] expression ] | * } ) 这时,可能 ...

  5. 基于springboot+kotlin+gradle构建的框架的坑

    项目采用以上技术构建,于是本人就尝试构建自己的脚手架,然后遇到一大推问题. 使用的是springinitials构建,IDE是:IDEA 现在也是知其然不知其所以然,但是先记录下来修改过程,以后等知识 ...

  6. POJ3009(dfs)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17672   Accepted: 7262 Desc ...

  7. Java-API-POI-Excel:XSSFWorkbook Documentation

    ylbtech-Java-API-POI:XSSFWorkbook Documentation 1.返回顶部 1. org.apache.poi.xssf.usermodel Class XSSFWo ...

  8. 关于64位操作系统使用C#访问注册表失败的问题

    通过C#的注册表类 Registry.GetValue 进行访问时,其返回值一直为空.然后认真检查检查再检查了注册表路径,发现路径没有一点问题,不说废话,上代码: if (Registry.GetVa ...

  9. NBU客户端备份失败,报错error 48 client hostname could not be found

    今天在做备份时发现了这个报错.经过ping, nslookup, bpclntcmd命令检查没有发现连接或域名解析存在问题. 参考文档http://www.symantec.com/docs/TECH ...

  10. NT AUTHORITY\IUSR登录失败解决方法

    NT AUTHORITY\IUSR登录失败解决方法 1 今天打开网站时,突然报这个错误,平时都好好的 Cannot open database "aslkm" requested ...