Installation and Use of XHProf (PHP performance testing tool)

Source: Internet
Author: User
: This article mainly introduces the installation and use of XHProf (PHP performance testing artifact). If you are interested in PHP tutorials, refer to it. XHProf is a performance debugging tool developed by Facebook to help optimize PHP programs and improve robustness. The installation and usage of XHProf are described in this chapter. XHProf is the PECL extension of PHP. There is no resource-consuming XDeBug, which is more compact. Process: start and end a program. Then, XHProf records the time, memory, CPU, and other indicators used to respond to all code between two points. we can also know how many times MySQL was called in a request, the number of Memcache times indicates the optimization path more intuitively. Installation: ------------ Download and compile PHP-XHProf source code ------------ wget http://pecl.php.net/get/xhprof-0.9.4.tgztar-zxvf xhprof-0.9.4.tgzcd xhprof-0.9.4cd extensionphpize. /configure -- enable-xhprofmakemake testsudo make install ------------ modify php. ini --------------- sudo vim/etc/php. ini # in php. add the following to the bottom of ini: extension = xhprof. soxhprof. output_dir = "/var/www/xhprof" ----------- restart Apache -------------- sudo apache restartGo to the unzipped installation package folder and copy xhprof_lib and xhprof_html to the project directory. Next, create a header file head. php, which is the starting point of the two points: // Head. php Create a bottom file foot. php, which is the end point of the two points: // Foot. php Save_run ($ xhprofData, $ ns); // The URL of the front-end display library $ url = 'http: // localhost/xhprof_html/index. php'; $ url. = '? Run = % s & source = % s'; // replace variable $ url = sprintf ($ url, $ runId, $ ns ); // enter the URL echo 'View result ';}The last step: hitting. Now we create a test file index. php. Test My Big Hello World. // Index. php You can see that in http: // localhost/index. in php, the bottom is in foot. click "View Results" written in php to view the list of all functions used in this request, including the time, CPU, and Memory consumed by each function, click the first column to sort by the selected order. Click [View Full Callgraph] to see the flowchart generated by this list, from the entry to which function, to which function, which function is called by this function, the number of times Memcache is called by this function. Reduce MC calls, reduce this, and reduce the request response speed? Tip: I have 1000 files. now I need to use XHProf to check my entire project. Do I need to add include to the header and tail of each file? Add the following in php. ini: Auto_prepend_file =/var/www/head. phpauto_append_file =/var/www/foot. phpOr add Php_value auto_prepend_file =/var/www/head. phpphp_value auto_append_file =/var/www/foot. phpError: 1. when you click [View Full Callgraph] to View the image, the following error occurs: failed to execute cmd: "dot-Tpng". stderr: 'Sh: dot: command not found '. Cause: The graphic tool is not installed: // Red Hat yum install graphviz // Ununtuapt-get install graphviz // OS Xbrew install graphviz

The above introduces the installation and use of XHProf (PHP performance testing artifact), including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.