Php lightweight debugging tool XHProf

Source: Internet
Author: User
XHProf is a lightweight debugging tool released by Facebook. Compared with Xdebug, XHProf is easier to use and controllable, especially for generating flowcharts and comparing debugging data.

XHProf is a lightweight debugging tool released by Facebook. Compared with Xdebug, XHProf is easier to use and controllable, especially for generating flowcharts and comparing debugging data.

: Http://pecl.php.net/package/xhprof

1. installation method:

# Wget http://pecl.php.net/get/xhprof-0.9.4.tgz# tar zxvf xhprof-0.9.4.tgz # cd xhprof-0.9.4 ### copy xhprof_html, xhprof_lib two directories to the personal application directory # cp-rp xhprof_html // home/wwwroot/www.test.com/# cp-rp xhprof_lib // home/wwwroot/www.test.com/# cd extension #/usr/local/php/bin/phpize #. /configure -- with-php-config =/usr/local/php/bin/php-config # make & make install
2. configure the php. ini file
Extension = "xhprof. so"; to set the log directory, you must have the permission to operate xhprof. output_dir = '/var/log/xhprof'

Restart the service.

View phpinfo:

In this way, xhprof is successfully installed. if you want to view the test result through the graphic interface, you need to install Graphviz.

3. install Graphviz

wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gztar zxvf graphviz-2.24.0.tar.gzcd graphviz-2.24.0./configuremakemake install
Add the generated/usr/local/bin/dot to the PATH, use vim to open/etc/profile, and add
PATH="$PATH:/usr/local/bin/dot"export PATH
Run the following command to make it take effect.
# source /etc/profile

4. use

Add the following content to the PHP file header:

Xhprof_enable (); // xhprof_enable (writable); built-in functions are not recorded // xhprof_enable (XHPROF_FLAGS_CPU + memory); CPU and Mem overhead analyzed at the same time $ xhprof_on = true; // available in the production environment: // if (mt_rand (1, 10000) = 1) {// xhprof_enable (); // $ xhprof_on = true ;//}
Add the following at the bottom of the PHP file:
If ($ xhprof_on) {$ xhprof_data = xhprof_disable (); $ xhprof_root = '/home/wwwroot/www.test.com/'{{de_once $ xhprof_root. "xhprof_lib/utils/xhprof_lib.php"; include_once $ xhprof_root. "xhprof_lib/utils/"; $ xhprof_runs = new XHProfRuns_Default (); $ run_id = $ xhprof_runs-> save_run ($ xhprof_data, "hx"); echo 'statistics ';}
Run the program and the statistical words appear at the bottom. click it to view the performance analysis. Sort by running time, and it is easy to find the function with the longest time.
Click [View Full Callgraph] for graphical display. the biggest performance problem is marked in red, followed by yellow, which is obvious.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.