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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM