XHProf is a PHP lightweight performance analysis tool open sourced by Facebook. It is similar to Xdebug, but has lower performance overhead. It can also be used in production environments, and can also be controlled by program switches to control whether to profile. . Overall, it is a good tool. The following describes the installation and usage process under Ubuntu.
Install xhprof:
wget http://pecl.php.net/get/xhprof-0.9.2.tgz tar zxf xhprof-0.9.2.tgz cd xhprof-0.9.2/extension/ sudo phpize ./configure --with-php-config=/usr/local/php/bin/php-config sudo make sudo make install
In order to view the debugging results graphically, you must also install the graphviz tool. Under ubuntu, you can directly use apt-get to install it. The command is: sudo apt-get install graphviz. If it is other systems, you have to go through many twists and turns. Click, the command is as follows:
wget http:<span //</span><span www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz</span> tar zxf graphviz-<span 2.24</span>.<span 0</span><span .tar.gz cd graphviz</span>-<span 2.24</span>.<span 0</span><span .</span>/<span configure make </span>&& make install
Configure php.ini
Add the following content to php.ini:
[xhprof]
extension=xhprof.so;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; >;
> )
After modification, restart apache and look at phpinfo. There should be xhprof related information.
<?pho // cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY // 如果两个一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); // 要测试的php代码 $data = xhprof_disable(); //返回运行数据 // xhprof_lib在下载的包里存在这个目录,记得将目录包含到运行的php代码中 include_once "xhprof_lib/utils/xhprof_lib.php"; include_once "xhprof_lib/utils/xhprof_runs.php"; $objXhprofRun = new XHProfRuns_Default(); // 第一个参数j是xhprof_disable()函数返回的运行信息 // 第二个参数是自定义的命名空间字符串(任意字符串), // 返回运行ID,用这个ID查看相关的运行结果 $run_id = $objXhprofRun->save_run($data, "xhprof"); var_dump($run_id); 查看运行结果
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
For 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.
http://www.bkjia.com/PHPjc/748243.html