【轉】給Windows + Apache 2.2 + PHP 5.3 安裝PHP效能測試工具 xhprof

來源:互聯網
上載者:User

標籤:

原文連結:http://blog.snsgou.com/post-816.html

 

1、下載XHProf

到這裡 http://dev.freshsite.pl/php-extensions/xhprof.html 下載Windows版本的XHProf,我這裡選擇下載

XHProf 0.10.3 for PHP 5.3 vc9 和 xhprof_html

 

2、安裝XHProf

把壓縮包裡的 xhprof_0.10.3_php53_vc9.dll 拷貝到PHP的ext目錄下,然後在php.ini配置裡面加入配置(不要忘記建立對應的檔案夾)

[xhprof]extension=xhprof_0.10.3_php53_vc9.dll; directory used by default implementation of the iXHProfRuns; interface (namely, the XHProfRuns_Default class) for storing; XHProf runs.xhprof.output_dir="d:/PHP/xhprof/log"

  

3、使用XHProf

將 xhprof_html.zip 解壓到你想測試的網站根目錄,如我放在了網站目錄的 /public/xhprof/windows 下。

測試檔案:

<?phpfunction bar($x){if ($x > 0){bar($x - 1);}}function foo(){for ($idx = 0; $idx < 5; $idx++){bar($idx);$x = strlen("abc");}}// 啟動xhprofxhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);// 調用foo函數,也是我們要分析的函數foo();// 停止xhprof$xhprof_data = xhprof_disable();// 取得統計資料//print_r($xhprof_data);$os = ‘windows‘;$XHPROF_ROOT = dirname(__FILE__) . ‘/public/xhprof/‘ . $os;include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";// 儲存統計資料,產生統計ID和source名稱$xhprof_runs = new XHProfRuns_Default();$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); // source名稱是xhprof_foo// 查看統計資訊echo "<div style=‘margin: 50px auto; padding :10px; width: 92px; font-size: 16px; background: #ff0000;‘><a style=‘color:#ffff00;‘ href=‘/public/xhprof/" . $os . "/xhprof_html/index.php?run=" . $run_id . "&source=xhprof_foo‘ target=‘_blank‘>XHProf view</a></div>";

  

當點選連結“[View Full Callgraph]”時,會報錯:

failed to execute cmd: " dot -Tpng"

所以還需要下載圖形工具 Graphviz

 

 

4、下載Graphviz

到這裡 http://www.graphviz.org/Download_windows.php 下載Windows版本的Graphviz,我這裡選擇下載  

graphviz-2.38.zip

 

5、安裝Graphviz

解壓後,把Graphviz拷貝到某個目錄,如 d:/PHP/xhprof/graphviz-2.38/

 

6、配置Graphviz

找到上述提到網站目錄 /public/xhprof/windows/ 下的 config.php 檔案,調整如下:

<?php/** * Set the absolute paths on your system */define(‘ERROR_FILE‘, ‘d:/PHP/xhprof/log/xhprof_dot_errfile.log‘);define(‘TMP_DIRECTORY‘, ‘d:/PHP/xhprof/tmp‘);define(‘DOT_BINARY‘, ‘d:/PHP/xhprof/graphviz-2.38/release/bin/dot.exe‘);

  重新點選連結 [View Full Callgraph],一張期待已久的出來啦:

 

 

 

【轉】給Windows + Apache 2.2 + PHP 5.3 安裝PHP效能測試工具 xhprof

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.