This article mainly introduces the PHP Performance test Tool XHPROF installation and use of the method, a simple description of the Performance test tool xhprof function and a more detailed analysis of the XHPROF installation and use of relevant operating skills, the need for friends can refer to the following
This article analyzes the PHP Performance test Tool Xhprof installation and use method. Share to everyone for your reference, as follows:
Xhprof Overview:
Xhprof is a layered PHP performance analysis tool. It reports the number of requests at the function level and various metrics, including blocking time, CPU time, and memory usage. The overhead of a function, which can be subdivided into the cost of the caller and the callee, xhprof the data collection phase, which records the number of calls to trace and an inclusive indicator of the arc in the dynamic callgraph of a program. It is unique to the reporting/post-processing phase of the data calculation. At data collection, XHPROFD handles recursive function calls by detecting loops and avoids the dead loop by invoking a useful name for each depth in the recursive call. The XHPROF Analysis report helps to understand the structure of the code being executed, and it has a simple HTML user interface (written in PHP). The browser-based performance analysis user interface makes it easier to view or share results with peers. The call graph can also be drawn.
Installation and use:
Recently to do the performance of the site comparison, so find a performance test work to play, tools a lot, but compared to before still feel xhprof installation and use relatively simple point, data analysis also can, the following said its installation and use ...
Download Xhprof and Graphviz
Xhprof words, directly to the PHP website can be downloaded, in order to facilitate you can poke a bit here
Graphviz words also want to download, mainly display xhprof performance results of the graphic report, Poke here
Compiling and installing Xhprof
CD Xhprof-0.9.4/xhprof-0.9.4/extension/phpize./configuremakesudo make install
Add the generated xhprof.so file to the php.ini file and restart Apache.
... #这里要使用相对路径加载的话首先要看一下extension_dir配置的路径, or simply write the '. So ' file to the absolute path ... Extension=xhprof.so...sudo apachectl restart# #测试扩展是否安装成功, the following output is okphp--ri xhprof ... xhprof xhprof = 0.9.2 CPU num =&G T 4 ...
Installing Graphviz
CD graphviz-2.38.0/#后面参数是要确保安装了libphp才行哦 "no installed brew install Linpng"./configure--with-png=yesmakesudo Make Install
Test it.
In the previously downloaded Xhprof folder, find the Xhprof_html,xhprof_lib, sample three folders, then the three folder is placed where you can access the place to go, and then through the connection to first access the following http://xxxx/sample/ sample.php, when you visit the following http://xxxx/xhprof_html/, you will see a record, click on the Analysis results page, click on the View full callgraph link to the graphical report page.
How to use
Suppose you want to look at the homepage performance data of a website that you do now, then you want to find this website homepage entry file, add xhprof performance test code before and after the core file is loaded
#开启, specific parameter descriptions can be viewed in the official document Xhprof_enable (Xhprof_flags_no_builtins | Xhprof_flags_cpu | xhprof_flags_memory); #核心文件的执行 require ' index.php ' ... #关闭 $xhprof _data = xhprof_disable (); #这里的路径根据自己的站点来配置 $XHPROF _ ROOT = Realpath (dirname (__file__). ' /'); include_once $XHPROF _root. "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF _root. "/xhprof_lib/utils/xhprof_runs.php"; $xhprof _runs = new Xhprofruns_default (); $run _id = $xhprof _runs->save_run ($ Xhprof_data, "Xhprof"), #这里打印出本次测试的id, convenient to the report List page "http://xxxx/xhprof_html/" to the corresponding ID to find the corresponding result Var_dump ($run _id);