Detailed explanation of PHP xhprof using examples


Performance analysis of xhprof PHP

1. Clone xhprof this version is a third-party extension of GitHub (PHP 7 is not supported in PHP official room)

2. The extension directory is an extended source security extension

phpize && ./configure && make && make install

3. Edit php.ini to enable xhprof extension

extension =
Xhprof. Output_dir = / TMP / xhprof; the storage location of performance analysis data files requires that PHP users have write and read permissions

4. Add code to the project entry file

register_shutdown_function(function (){
$data = xhprof_disable();  
  //Xhprof? Lib is in the folder after the first step git clone 
  include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_lib.php';
  include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_runs.php';
  $objXhprofRun = new XHProfRuns_Default();
  $objxhprofrun - > Save run ($data, "table"); // generate data file suffix

5. Nginx or Apache creates the directory of network occupation (APACHE as an example)

<VirtualHost *:80>
  ##Xhprof / xhprof? HTML in the folder after the first step git clone
  DocumentRoot "/mnt/d/www/xhprof/xhprof_html"
  DirectoryIndex index.html index.php index.html
  <Directory "/mnt/d/www/xhprof/xhprof_html">
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted

6. Visit (the local domain name configured by the virtual host above requires host) to display the performance analysis data file generated by each program run. Click to open it

7. If you want to view the performance chart, click View full callgraph (the server needs to install the graphviz Library)

Ubuntu installation method(pro apt-get install graphviz

8. Display renderings


The above is a detailed explanation of the PHP xhprof application example that Xiaobian introduced to you, hoping to help you. If you have any questions, please leave a message to me, and Xiaobian will reply you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Recommended Today

Introduction to GitHub Xiaobai (1) interface

Like many Xiaobai, I am also a headache when I see a lot of words and pictures. The following GitHub tutorial, combined with my own understanding, is told in an easy-to-understand way, with the purpose of explaining clearly. Next, start learning with me! 1. GIT and GitHub Guide: let’s first understand what GIT and GitHub […]