This article describes how to install and use the PHP performance analysis tool XHProf. This article provides detailed installation steps, configuration methods, and examples, for more information, see HProf, a lightweight php performance analysis tool developed by facebook. it is similar to Xdebug, but has lower performance overhead and can be used in production environments, you can also enable or disable profile control. Browser-based
The performance analysis user interface of the tool is easier to view or share the results with colleagues. The call relationship diagram can also be drawn. In the data collection phase, it records call times tracking and inclusive indicator arcs in a dynamic callgraph program.
It is unique in the report/post-processing phase of data computing. During data collection, XHProfd processes recursive function calls through a detection loop, and avoids an endless loop by giving a useful name to calls in every depth in a recursive call.
XHProf's lightweight nature and aggregation feature make it ideal for collecting performance statistics for the "production environment.
1. install XHProf
The code is as follows:
Wget http://pecl.php.net/get/xhprof-0.9.2.tgz
Tar zxf xhprof-0.9.2.tgz
Cd xhprof-0.9.2
Cp-r xhprof_html xhprof_lib
Cd extension
Phpize
./Configure
Make
Make install
2. configure the php. ini file
The code is as follows:
[Xhprof]
Extension = xhprof. so
;
; Directory used by default implementation of the iXHProfRuns
; Interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
; Remember The WEB must have write permission
Xhprof. output_dir =
Restart the service to make the modification take effect. now you can use XHProf. However, it is best to continue to install Graphviz to make the change more effective.
3. install Graphviz
The code is as follows:
Wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz
Tar zxf graphviz-2.26.3.tar.gz
Cd graphviz-2.26.3
./Configure
Make
Make install
After the installation is complete, the/usr/local/bin/dot file is generated. make sure that the PATH is in the PATH environment variable so that XHProf can find it.
4. apply XHProf
The code is as follows:
Xhprof_enable (); // open xhprof
/****** Program logic Start ******/
Function test1 (){
Sleep (3 );
Return;
}
Function test2 (){
Test1 ();
}
Function test3 (){
Test2 ();
}
Function p (){
Echo 'xhprof test ';
}
P ();
Test3 ();
/****** End of program logic ******/
$ Xhprof_data = xhprof_disable (); // disable xhprof
// Save xhprof data
Include_once '../xhprof_lib/utils/xhprof_lib.php ';
Include_once '../xhprof_lib/utils/xhprof_runs.php ';
$ Xhprof_runs = new XHProfRuns_Default ();
$ Xhprof_source = 'xhprof _ test ';
$ Run_id = $ xhprof_runs-> save_run ($ xhprof_data, $ xhprof_source );
$ Report_url = 'http: // xhprof.rebill.info/index.php? Run = '. $ run_id.' & source = '. $ xhprof_source;
Echo'
';
Echo 'View the performance report: '. $ report_url .'';
In this way, the data file named 4c236583ef490. xhprof_test will be generated in the xhprof. output_dir directory set above, which allows you to easily view the effect through the Web:
Http://xhprof.rebill.info/index.php? Run = 4c236583ef490 & source = xhprof_test
Currently, table display is displayed. click [View Full Callgraph] on the page to View the exquisite picture.
Online test experience address: http://xhprof.rebill.info/test.php