php效能監控擴充xhprof_PHP教程

來源:互聯網
上載者:User
XHProf是facebook開源出來的一個php輕量級的效能分析工具,跟Xdebug類似,但效能開銷更低,還可以用在生產環境中,也可以由程式開 關來控制是否進行profile。總體來說是個不錯的工具,下面介紹下在ubuntu下的安裝及使用過程。

安裝xhprof:

wget http://pecl.php.net/get/xhprof-0.9.2.tgztar zxf xhprof-0.9.2.tgzcd xhprof-0.9.2/extension/sudo phpize./configure --with-php-config=/usr/local/php/bin/php-configsudo makesudo make install

  

為了使用圖形方式查看調試結果,還必須安裝graphviz這個工具,在ubuntu下你可以直接使用apt-get的方式安裝,命令為:sudo apt-get install graphviz,如果是其他系統,那得曲折點,命令如下:

wget http:tar zxf graphviz-.-./&& make install


配置 php.ini

在php.ini裡加入如下內容:

[xhprof]
extension=xhprof.so;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
;xhprof.output_dir=
xhprof.output_dir=/tmp/xhprof
注:如果是64位系統需要將xhprof.so檔案拷貝到相關的lib目錄下(lib64)

修改之後重啟下apache,看下phpinfo,應該有xhprof的相關資訊了吧。

將代碼加入到要測試的php當中

save_run($data, "xhprof");var_dump($run_id);查看運行結果

  

將xhprof_lib&&xhprof_html相關目錄copy到可以訪問到的地址

訪問 xxx/xhprof_html/index.php?run=$run_id就可經看到你的php代碼啟動並執行相關情況,其中$run_id就是上面頁面中輸出的內容,記得一定要包含

xhprof_lib下的兩個檔案,如果不想通過這個方式的話也可以直接輸出相關的列印資訊,即直接print_r出上面的$data的值。

http://www.bkjia.com/PHPjc/748243.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/748243.htmlTechArticleXHProf是facebook開源出來的一個php輕量級的效能分析工具,跟Xdebug類似,但效能開銷更低,還可以用在生產環境中,也可以由程式開 關來控制...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.