php运行速度检测软件,PHP执行慢分析工具xdebug + webgrind
經常碰到用戶PHP網站打開速度慢,運維環境配置的鍋?PHP代碼的鍋?當你發現程序變慢,但有時我們不知道具體是哪塊代碼執行慢(排除環境問題),或者哪個方法占用了太長的執行時間,這時我們就需要一個調試工具,來幫我們記錄程序執行過程中的一些具體信息,包括類、方法名、執行時間、次數等信息,今天介紹的工具是xdebug以及他的結果分析展示工具webgrind。
xdebug安裝
cd /root/oneinstack/src
wget https://xdebug.org/files/xdebug-2.5.5.tgz
tar xzf xdebug-2.5.5.tgz
cd xdebug-2.5.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
php加載xdebug模塊
cat > /usr/local/php/etc/php.d/ext-xdebug.ini << EOF
[xdebug]
zend_extension=xdebug.so
xdebug.trace_output_dir=/tmp/xdebug
xdebug.profiler_output_dir = /tmp/xdebug
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = 1
EOF
創建xdebug目錄
mkdir /tmp/xdebug
chown www.www /tmp/xdebug
webgrind安裝
webgrind是php代碼,依賴PHP環境, 將webgrind代碼拷貝到你的apache或者nginx的web路徑下,可以正常訪問.
cd /data/wwwroot/www.example.com
git clone https://github.com/jokkedk/webgrind.git
chown -R www.www /data/wwwroot/www.example.com
vim /data/wwwroot/www.example.com/webgrind/config.php
static $storageDir = '/tmp/webgrind';
static $profilerDir = '/tmp/xdebug';
創建webgrind目錄
mkdir /tmp/webgrind
chown www.www /tmp/webgrind
分析
然后運行你的php項目,這時xdebug會在/tmp/xdebug/下生成一個 cachegrind.out.* 的文件。在頁面打開webgrind首頁。
Invocation Count:函數調用次數
Total Self Cost:函數本身花費的時間
Total Inclusive Cost:包含內部函數花費的時間
總結
以上是生活随笔為你收集整理的php运行速度检测软件,PHP执行慢分析工具xdebug + webgrind的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: python try expect 多个
- 下一篇: springboot日志配输出路径配置_
