Heim > php教程 > php手册 > Hauptteil

xhprof给你的PHP程序做个Profiler

WBOY
Freigeben: 2016-06-06 20:07:25
Original
899 Leute haben es durchsucht

xhprof是Fackbook开源的一个PHP代码“跟踪”程序,可以生成php程序的“函数”调用关系图,以及各个“函数”调用的次数及花费的时间。 当下,xhprof已经入住PHP的PECL库,可以能过pecl install xhprof安装(可能会提示你需要使用带版本号的名字,比如pecl ins

xhprof是Fackbook开源的一个PHP代码“跟踪”程序,可以生成php程序的“函数”调用关系图,以及各个“函数”调用的次数及花费的时间。

当下,xhprof已经入住PHP的PECL库,可以能过pecl install xhprof安装(可能会提示你需要使用带版本号的名字,比如pecl install xhprof-0.9.2)。

也可以下载源代码编译安装(其实与使得pecl安装效果是一样的)。

当使用php 5.4时,安装xhprof可能会遇到麻烦,详情见这个bug公告:https://bugs.php.net/bug.php?id=61674,为xhprof-0.9.2打上补丁即可编译通过:https://github.com/facebook/xhprof/commit/a6bae51236.diff

下面说xhprof怎么使用。

配置xhprof:
在原php的配置文件加入
[xhprof]
extension=xhprof.so
xhprof.output_dir=’/var/tmp’

/var/tmp目录需要apache运行账号可写。

安装绘图工具graphviz,这个是xhprof调用用来绘图的。

RHEL6上可以使用yum直接安装:yum install graphviz。或者自己编译安装。

为xhprof配置个专用的web访问路径:

比如在/etc/http/conf.d/下建一个xhprof.conf配置文件,内容如下:

Alias /xhprof/ /usr/share/pear/xhprof_html/

Options -indexes
Order allow,deny
Allow from all

使用xhprof:

// 放在程序开始第一行
xhprof_enable();

// 原程序开始

// 原程序结束

// 放在结尾
$xhprof_data = xhprof_disable();

$XHPROF_ROOT = ‘/usr/share/pear/’;
include_once $XHPROF_ROOT . “/xhprof_lib/utils/xhprof_lib.php”;
include_once $XHPROF_ROOT . “/xhprof_lib/utils/xhprof_runs.php”;

$xhprof_runs = new XHProfRuns_Default();

$run_id = $xhprof_runs->save_run($xhprof_data, “xhprof_foo”);

访问统计结果:

http://www.bsdmap.com/xhprof/index.php?run=$run_id&source=xhprof_foo

其中run_id到xhprof.output_dir设定的目录中查找。

给个例子:

http://www.bsdmap.com/xhprof/index.php?run=502e093694815&source=xhprof_foo

参考:
http://hi.baidu.com/thinkinginlamp/blog/item/f4bd08fa1a03ba9e59ee90fd.html
https://bugs.php.net/bug.php?id=61674

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!