Php performance monitoring extension xhprof performance analysis tool

Source: Internet
Author: User
Php performance monitoring extension xhprof performance analysis tool

Php performance monitoring extension xhprof is a good tool in general. This section describes how to install and use it in ubuntu.

Install xhprof:

  1. Wget http://pecl.php.net/get/xhprof-0.9.2.tgz
  2. Tar zxf xhprof-0.9.2.tgz
  3. Cd xhprof-0.9.2/extension/
  4. Sudo phpize
  5. ./Configure -- with-php-config =/usr/local/php/bin/php-config
  6. Sudo make
  7. Sudo make install

To view the debugging result in graphical mode, you must install graphviz. in ubuntu, you can directly install graphviz using apt-get. the command is sudo apt-get install graphviz. If it is another system, it may take twists and turns. the command is as follows:

  1. Wget http://www.graphviz.org/pub/graphviz/stable/sources/graphviz-2.24.0.tar.gz
  2. Tar zxf graphviz-2.24.0.tar.gz
  3. Cd graphviz-2.24.0
  4. ./Configure
  5. Make & make install

Configure php. ini

Add the following to php. ini:

  1. [Xhprof]
  2. Extension = xhprof. so;
  3. ; Directory used by default implementation of the ixhprofruns
  4. ; Interface (namely, the xhprofruns_default class) for storing
  5. ; Xhprof runs.
  6. ;
  7. ; Xhprof. output_dir =
  8. Xhprof. output_dir =/tmp/xhprof

Note: For a 64-bit system, copy the xhprof. so file to the relevant lib Directory (lib64)

After the modification, restart apache and check phpinfo. There should be information about xhprof.

Add the code to the php to be tested

  1. // Cpu: xhprof_flags_cpu memory: xhprof_flags_memory
  2. // If the two are together: xhprof_flags_cpu + xhprof_flags_memory
  3. Xhprof_enable (xhprof_flags_cpu + xhprof_flags_memory );
  4. // Php code to be tested
  5. $ Data = xhprof_disable (); // return the running data
  6. // This directory exists in the downloaded package. remember to include the directory in the running php code.
  7. Include_once "xhprof_lib/utils/xhprof_lib.php ";
  8. Include_once "xhprof_lib/utils/xhprof_runs.php ";
  9. $ Objxhprofrun = new xhprofruns_default ();
  10. // The first parameter j is the running information returned by the xhprof_disable () function.
  11. // The second parameter is a custom namespace string (any string ),
  12. // Return the running id. use this id to view the relevant running result.
  13. $ Run_id = $ objxhprofrun-> save_run ($ data, "xhprof ");
  14. Var_dump ($ run_id );

View the running result: copy the xhprof_lib & xhprof_html directory to the accessible address.

Access xxx/xhprof_html/index. php? Run = $ run_id: you can see the running status of your php code. $ run_id is the content output on the above page. remember to include two files under xhprof_lib, if you do not want to use this method, you can directly output the relevant print information, that is, directly print the $ data value above.

Parameter description:

Implicit time includes all execution times of sub-functions. Exclusive time/self time: the time consumed by the function execution, excluding the time consumed by the subtree. The time that wall time took or the time when the wall clock was suspended. Cpu time user consumed time + kernel consumed time: cpu occupied by the cpu exclusive function itself, including the cpu occupied by the cpu used by the sub-function

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.