Home Backend Development PHP Tutorial PHP performance monitoring extension xhprof performance analysis tool

PHP performance monitoring extension xhprof performance analysis tool

Jul 25, 2016 am 09:13 AM

The PHP performance monitoring extension xhprof is generally a good tool. This section introduces the installation and usage process under 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
Copy the code

In order to view the debugging results graphically, you must also To install the tool graphviz, you can directly use apt-get to install it under ubuntu. The command is: sudo apt-get install graphviz. If it is another system, you may have to use some 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
Copy the code

Next configure php.ini

Add in 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 =<directory_for_storing_xhprof_runs>
  8. xhprof.output_dir=/tmp/xhprof
Copy code

Note: If it is a 64-bit system, you need to copy the xhprof.so file to the relevant lib directory (lib64)

After modification, restart apache and look at phpinfo. There should be information about xhprof.

Add the code to the php to be tested

  1. <?php
  2. // cpu:xhprof_flags_cpu Memory: xhprof_flags_memory
  3. // If both together: xhprof_flags_cpu + xhprof_flags_memory
  4. xhprof_enable(xhprof_flags_cpu + xhprof_ flags_memory);
  5. //PHP code to be tested
  6. $data + /utils/xhprof_runs.php";
  7. $objxhprofrun = new xhprofruns_default();
  8. // The first parameter j is the running information returned by the xhprof_disable() function
  9. // The second parameter is the custom namespace character String (any string),
  10. //Return the running id, use this id to view the relevant running results
  11. $run_id = $objxhprofrun->save_run($data, "xhprof");
  12. var_dump($run_id);
  13. Copy the code
View the running results: Copy the xhprof_lib&&xhprof_html related directories to an accessible address Visit xxx/xhprof_html/index.php?run=$run_id to see the running status of your php code. $run_id is the content output in the above page. Remember to include the two files under xhprof_lib. If you don't want to use this method, you can also directly output the relevant printing information, that is, directly print_r out the value of $data above.

Parameter description:

Inclusive time includes all execution time of sub-functions. exclusive time/self time The time it takes for the function to execute itself, excluding subtree execution time. wall time elapsed time or wall clock time. cpu time user time + kernel time inclusive cpu includes the cpu occupied by sub-functions together exclusive cpu The cpu occupied by the function itself

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

6 Extra Skills Every PHP Developer Should Have 6 Extra Skills Every PHP Developer Should Have Feb 28, 2025 am 10:52 AM

6 Extra Skills Every PHP Developer Should Have

Understand Arrays in PHP Understand Arrays in PHP Feb 28, 2025 am 10:53 AM

Understand Arrays in PHP

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

See all articles