Installation and use of Xhprof (PHP performance test artifact)

Source: Internet
Author: User
Tags php error
Xhprof is a performance tuning tool developed by Facebook to help our PHP programs perform better and more robustly. Xhprof installation and use methods will be explained in this chapter. Xhprof is the pecl extension of PHP. There is no xdebug that consumes resources and is more compact. Process: The program starts with a dot and ends with a dot. So xhprof the opportunity to record the time, memory, CPU and other metrics that are spent on all code responses between two points, we can also know how many times MySQL was called, how many times memcache, and more visually indicate the path to optimization. Installation: ------------download and compile php-xhprof source------------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# add the following to the bottom of php.ini: extension= Xhprof.soxhprof.output_dir= "/var/www/xhprof"-----------restart Apache--------------sudo apache restartGo to the installation package folder that you just unzipped, and copy the Xhprof_lib and xhprof_html to the project directory. Next, create a header file head.php, which is the point to hit the beginning of two points: head.php Then build a bottom file foot.php, which is going to hit the end point in 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 '; Variable substitution $url = sprintf ($url, $runId, $ns); Enter the URL echo ' view results ';}Last step in use: Dot. Now we build a test file index.php. Test me big Hello World. index.php Can see, in the http://localhost/index.php, the bottom is we write in the foot.php "View Results", click into, you can see this request to use the list of all functions, the time spent on each function, CPU, memory and other information, Click the first column to sort by the selection. Click [View full CallGraph] to see the flow chart generated by this list, from the entrance to which function, and to which function, which function called, the function called How many times memcache, and so on. Reduce the call of MC, reduce this, reduce that, the response speed of the request can not be unpleasant? Tip: I have 1000 files and now I need to test my entire project with xhprof, should I add an include to each file header and tail? Add in php.ini: Auto_prepend_file =/var/www/head.phpauto_append_file =/var/www/foot.phpor add in. htaccess Php_value Auto_prepend_file =/var/www/head.phpphp_value Auto_append_file =/var/ www/foot.php Error: 1, click [View full CallGraph] When viewing the image error: Failed to execute cmd: "Dot-tpng". stderr: ' Sh:dot:command not found '. Cause: Reason: No graphical tool installed: //Red Hat series Yum install graphviz//ununtuapt-get install Graphviz//os xbrew Install Graphviz

Above describes the installation and use of Xhprof (PHP performance test artifact), including aspects of the content, I hope to be interested in the PHP tutorial friends helpful.

  • 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.