Home >Backend Development >PHP Tutorial >Install PHP performance testing tool xhprof for Windows + Apache 22 + PHP 53
Original link: http://blog.snsgou.com/post-816.html
1. Download XHProf
Go here http://dev.freshsite.pl/php-extensions/xhprof.html to download the Windows version XHProf, I choose to download
XHProf 0.10.3 for PHP 5.3 vc9 and xhprof_html
2. Install XHProf
and copy the xhprof_0.10.3_php53_vc9.dll in the compressed package to the ext directory of PHP, and then in php Add the configuration to the .ini configuration (don’t forget to create the corresponding folder)
[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. Use XHProf
to unzip xhprof_html.zip to the root directory of the website you want to test, for example, I placed it in the website directory / Under public/xhprof/windows.
Test file:
<?php function bar($x) { if ($x > 0) { bar($x - 1); } } function foo() { for ($idx = 0; $idx < 5; $idx++) { bar($idx); $x = strlen("abc"); } } // 启动xhprof xhprof_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; <strong>include</strong>_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; <strong>include</strong>_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><a href='/public/xhprof/" . $os . "/xhprof_html/index.php?run=" . $run_id . "&source=xhprof_foo' target='_blank'>XHProf view</a></div>";
When clicking the link "[View Full Callgraph]", an error will be reported:
failed to execute cmd: " dot -Tpng"
So you also need to download the graphics tool Graphviz.
4. Download Graphviz
Go here http://www.graphviz.org/Download_windows.php to download the Windows version of Graphviz. I choose to download
graphviz-2.38.zip
5. Install Graphviz
After decompression , copy Graphviz to a directory, such as d:/PHP/xhprof/graphviz-2.38/
6. Configure Graphviz
Find the config.php under the above mentioned website directory /public/xhprof/windows/ file, adjusted as follows:
<?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');
Re-click the link [View Full Callgraph], and a long-awaited rendering comes out:
The above introduces the installation of the PHP performance testing tool xhprof for Windows + Apache 22 + PHP 53, including the include content. I hope it will be helpful to friends who are interested in PHP tutorials.