Detailed explanation of PHP xhprof using examples

Time:2020-2-10

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)

https://github.com/longxinH/xhprof

2. The extension directory is an extended source security extension

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

3. Edit php.ini to enable xhprof extension

[xhprof]
extension = xhprof.so
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

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS +
XHPROF_FLAGS_CPU +
     XHPROF_FLAGS_MEMORY);
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>
  ServerName xhprof.com
  ##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
  </Directory>
 </VirtualHost>

6. Visit http://xhprof.com/ (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

summary

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

Using docker / docker compose to deploy software applications

Swoft The first high-performance PHP full stack framework based on swoole native orchestration in the new era, built-in orchestration network server and commonly used orchestration client, resident in memory, independent of traditional php-fpm, fully asynchronous non blocking IO implementation, similar to synchronous client writing to achieve asynchronous client use, no complex asynchronous callback, no tedious […]