• notice
  • Congratulations on the launch of the Sought Tech site

Use the XHProf extension to test the performance of php programs-troubleshoot PHP performance bottlenecks

    Before I simply used webgrind to test the performance of PHP programs, today I recommend another performance test Tool: XHProf extension.
    XHProf is a performance debugging tool developed by Facebook.It can help visually display the number of calls and time consumption of each method function in the execution of PHP programs, so as to facilitate us to troubleshoot performance bottlenecks and perform tuning.What's more convenient is that XHProf can draw a call relationship graph.The longest execution process will be marked with obvious thick lines and colors.The process and bottlenecks during the execution of the entire program are clear at a glance.Compared to XDeBug, XHProf is a PECL extension of PHP.It saves resources and is more compact than XDeBug.

    Installation of XHProf: The current latest version is version 0.9.4

< span class="pln">cd /usr/local< span class="kwd">local/php/bin/php-< /span>config make && make install
The installation is the same as installing other PHP extensions.After completion, add the extension to php.ini.But in addition, you need to add a configuration, as follows:


span>=< span class="pln">xhprof
.so xhprof. span>output_dir="/tmp/xhprof" #Specify the storage directory of the performance statistics file
Restart php.It is also very simple to use: add the program at the beginning of the entire program:< br>xhprof_enable();  #Open performance analysis
    Note: Because the analysis process needs to load some PHP programs that have been written by xhprof, and the results are displayed in WEB form charts, so Need to call some programs that have been written by xhprof.There is a xhprof_lib directory and xhprof_html directory in the installation directory: these two directories need to be placed in the WEB program before using the xhprof function (stored side by side, and ensure that the xhprof_html directory can be accessed through http),


Technical otaku

Sought technology together

Related Topic


Leave a Reply