For a long time, I have used a small plug-in written by myself for PHP debugging and running performance monitoring, and I feel that it is okay. But when I was browsing around just now, I found something called Xhprof. After a brief look at the introduction, it seemed to be similar to my little plug-in. I would like to sort out the applications of Xhprof and compare it with my plug-in.
Official website
<code><span>http:</span>//www<span>.xhprof</span><span>.com</span>/</code>
Install
<code>wget http:<span>//pecl.php.net/get/xhprof-0.9.4.tgz</span> tar zxf xhprof<span>-</span><span>0.9</span><span>.4</span><span>.</span>tgz cd xhprof<span>-</span><span>0.9</span><span>.4</span>/extension<span>/</span> phpize <span>.</span>/configure <span>--</span><span>with</span><span>-php</span><span>-config</span><span>=</span>/usr/<span>local</span>/php/bin/php<span>-config</span> make make install</code>
Configure PHP.ini
<code><span># vi /usr/local/php/etc/php.ini</span></code>
<code>[xhprof] extension=xhprof<span>.so</span><span>;</span> xhprof<span>.output</span>_dir=/tmp/xhprof</code>
Application 1
<code><span><span><?php</span> xhprof_enable(); 【PHP业务代码】 <span>$data</span> = xhprof_disable(); <span>// xhprof_lib在下载的包里存在这个目录,记得将目录包含到运行的php代码中</span><span>include_once</span><span>"xhprof_lib/utils/xhprof_lib.php"</span>; <span>include_once</span><span>"xhprof_lib/utils/xhprof_runs.php"</span>; <span>$objXhprofRun</span> = <span>new</span> XHProfRuns_Default(); <span>// 第一个参数j是xhprof_disable()函数返回的运行信息</span><span>// 第二个参数是自定义的命名空间字符串(任意字符串),</span><span>// 返回运行ID,用这个ID查看相关的运行结果</span><span>$run_id</span> = <span>$objXhprofRun</span>->save_run(<span>$data</span>, <span>"xhprof"</span>); var_dump(<span>$run_id</span>);</span></span></code>
Application 2
<code><span><span><?php</span><span>//cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY,这两个都是整形常量,可以相加</span> xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); 【PHP业务代码】 <span>$data</span> = xhprof_disable(); </span></code>
The above has introduced the Xhprof application, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.