欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

php性能分析利器xhprof扩展安装(php5.6.31) 5.5 版本也行 自己亲自做的 有大用 有大大用 有大大大用

php性能分析利器xhprof扩展安装(php5.6.31)
发布于2017年10月06日    作者:苏南大叔    来源:程序如此灵动~
如果本文对您有帮助,或者节约了您的时间,欢迎打赏瓶饮料,建立下友谊关系。
本博客不欢迎:各种镜像采集行为。请尊重原创文章内容,转载请保留链接信息。
苏南大叔在本篇文章中,给大家要说的是,老牌的php性能分析利器xhprof。不过这款利器,已经很多年没有更新了。本文的写作环境是php5.6.31。截至到本文发布时为止,xhprof的官方版本,并不支持php7系列的性能分析。对于php7下xhprof的安装,请参见文末相关链接。

下载xhprof源码
官方版本的源码下载地址是:http://pecl.php.net/package/xhprof 。 (这个地址有大用)


php性能分析利器xhprof扩展安装(php5.6.31)(图7-1)
编译扩展
xhprof的扩展编译和phptrace等其他扩展的编译,过程基本类似。可能出现的问题也基本相同。大家可以参考一下,苏南大叔以前的扩展编译相关文章。

Batch
which php-config
cd xhprof-0.9.4/extension/
phpize                
./configure --with-php-config=
make && sudo make install


我的作法是 

#   wget http://pecl.php.net/get/xhprof-0.9.4.tgz

#   tar zxvf xhprof-0.9.4.tgz

#   cd xhprof-0.9.4/extension

#  /www/wdlinux/apache_php-5.5.38/bin/phpize

 ./configure --with-php-config=/www/wdlinux/apache_php-5.5.38/bin/php-config

# make && make install

# vim /www/wdlinux/apache_php-5.5.38/etc/php.ini

[xhprof]

extension=/www/wdlinux/apache_php-5.5.38/lib/php/extensions/no-debug-non-zts-20121212/xhprof.so

xhprof.output_dir=/home/wwwroot/aaaaa/public_html/xhprof   


/home/wwwroot/aaaaa/public_html/xhprof 这个目录 php应该有访问权限吧


# service httpd restart   ( 如果是nginx  可能 service nginxd restart没用,可能需要重新启动电脑,因为nginx重启,不代表fastcgi (php的服务器)重启)

打开 phpinof页面 看看 有没有 xhprof

image.png





对于configure命令中的php-config-path,需要使用which php-config命令的结果来代替即可。
AD:PHP高手都在这里,就差你了

php性能分析利器xhprof扩展安装(php5.6.31)(图7-2)


php性能分析利器xhprof扩展安装(php5.6.31)(图7-3)
AD:PHP高手都在这里,就差你了

php性能分析利器xhprof扩展安装(php5.6.31)(图7-4)


php性能分析利器xhprof扩展安装(php5.6.31)(图7-5)
注意对比一下,最终install的地址是否是phpinfo()里面的扩展目录地址。如果不是,可能需要主动复制一下才行。

修改php.ini启用xhprof
[xhprof]
extension = xhprof.so
xhprof.output_dir = /tmp/xhprof


php性能分析利器xhprof扩展安装(php5.6.31)(图7-6)
重启验证是否生效
phpinfo中出现了xhprof的相关信息,不过这个版本号似乎有些问题。从pecl.php.net下载的0.9.4版本,编译后居然是0.9.2版本号。在https://github.com/phacility/xhprof 下载到的也是0.9.2版本。可能是官方忘了修改版本号了。

AD:PHP高手都在这里,就差你了

php性能分析利器xhprof扩展安装(php5.6.31)(图7-7)
相关文章
https://newsn.net/say/php7-xhprof-install.html
写在最后
欢迎继续查看苏南大叔的后续xhprof文章: https://newsn.net/tag/xhprof/


转载请注明来源:
作者:苏南大叔
原文:
https://newsn.net/say/php5-xhprof-install.html


来自  https://newsn.net/say/php5-xhprof-install.html


如何使用php代码分析工具xhprof
发布于2017年10月08日    作者:苏南大叔    来源:程序如此灵动~
如果本文对您有帮助,或者节约了您的时间,欢迎打赏瓶饮料,建立下友谊关系。
本博客不欢迎:各种镜像采集行为。请尊重原创文章内容,转载请保留链接信息。
相比较phptrace、xdebug,xhprof的功能更加强大,但是对于代码来说,它是侵入式的。其基本功能的基础是要对php源码进行修改,必须嵌入这个扩展的相关代码,才能实现其强大的功能。所以,这样来说,是不是方便大家使用,就仁者见仁智者见智了。

苏南大叔将简要介绍一下xhprof的使用,本文的写作环境是php5.6.31下的xhprof,至于php7.2.0b3下的xhprof,虽然编译成功。但是在实际运行中,还是有一定的概率导致502错误。所以,这里并没有采用这个环境。大家如果要在php7下面使用xhprof的话,就还需要三思而行。详细的中文介绍,可以点击这里查看:https://doc.php.sh/zh/book.xhprof.html

放置库文件
代码需要能够访问到这两个目录,xhprof_lib和xhprof_html。但是这两个目录是否放置于网站根目录,就不一定了。对于xhprof_lib来说,需要能够被include到。而xhprof_html,需要能够通过地址访问到。所以,如果你不会配置nginx或者apache,那么简单的把这两组文件复制到网站根目录下面,是最好的选择。


如何使用php代码分析工具xhprof(图8-1)
对比sample.php埋点
官方源码里面有个examples/sample.php文件。


如何使用php代码分析工具xhprof(图8-2)
对比官方源码里面的example.php。我们可以知道:埋点分为两部分。
一部分是放在php文件主代码之前,见下面。

PHP
//date_default_timezone_set("Asia/Hong_Kong");
include_once "./xhprof_lib/utils/xhprof_lib.php";
include_once "./xhprof_lib/utils/xhprof_runs.php";
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
一部分是放在php文件主代码结束之,见下面。

PHP
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
//$run_id = $xhprof_runs->save_run($xhprof_data, str_replace(".", "_", basename(__FILE__)));
运行代码,写入日志
运行代码后,就会按着php.ini中的『xhprof.output_dir = /tmp/xhprof』的设定,写入日志文件。所以,请确保对应的文件夹权限。

AD:PHP高手都在这里,就差你了

如何使用php代码分析工具xhprof(图8-3)
查看分析
运行 http:///xhprof_html/ 即可查看相关结果。当然这个前提是,你已经成功放置了xhprof_lib和xhprof_html这两个文件夹。正常情况下,是这样的效果。


如何使用php代码分析工具xhprof(图8-4)

AD:PHP高手都在这里,就差你了
如何使用php代码分析工具xhprof(图8-5)


如何使用php代码分析工具xhprof(图8-6)

funciton name : 函数名
calls: 调用次数
Incl. Wall Time (microsec): 函数运行时间(包括子函数)
IWall%:函数运行时间(包括子函数)占比
Excl. Wall Time(microsec):函数运行时间(不包括子函数)
EWall%:函数运行时间(不包括子函数)
可能需要安装的组件
如果最后一步,查看图表失败的话。如下图所示:
AD:PHP高手都在这里,就差你了

如何使用php代码分析工具xhprof(图8-7)

请安装graphviz即可。(centos下面是yum install)
Batch
brew install graphviz


如何使用php代码分析工具xhprof(图8-8)
小小的进阶
苏南大叔说了,这种调用方式,对代码本身是有侵入性的。事实上不是太友好。那么进阶的操作就是,把上述两个注入点,用下面的形式改写成一个单独的文件。

PHP
//开启xhprof
xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);
//在程序结束后收集数据
register_shutdown_function(function() {
$xhprof_data = xhprof_disable();
//让数据收集程序在后台运行
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
//保存xhprof数据
...
});
然后利用php.ini的auto_prepend_file功能,来把这个文件自动注入到源码中。这个idea其实是相当不错的。几乎把代码的侵入性降到了最低点。

auto_prepend_file = /opt/inject.php
当然,也可以通过nginx修改php.ini。效果是差不多的。

Batch
fastcgi_param PHP_VALUE "auto_prepend_file=/opt/inject.php";
基本的使用教程就是这样的,更多有关xhprof的中文介绍。可以点击这里查看,https://doc.php.sh/zh/book.xhprof.html 。苏南大叔编写的xhprof系列教程,可以点击这里查看。https://newsn.net/tag/xhprof/

  【php】秘籍文章入口,仅传授于有缘之人  php    xhprof

欢迎转载传播本篇原创文章,转载请保留链接及作者信息。
本站采用创作共用版权协议, 要求署名、非商业用途和相同方式共享。 
转载本站内容必须也遵循“署名-非商业用途-相同方式共享”的创作共用协议。
《程序如此灵动~》下所有原创文章,如被用于商业用途,请您按规定支付稿费。
苏南大叔需要你的支持
打赏任意金额,发送截图到邮箱 shang@newsn.net ,可以领取精选回馈如下(任选其一):
《前端视频教程大礼包》一套
《wordpress精选皮肤》一套
《dedecms织梦精选模板》一套
感谢您的打赏,让我更有动力,将更多精彩教程文章,呈现给大家!谢谢!


转载请注明来源:
作者:苏南大叔
原文:https://newsn.net/say/xhprof-123.html


来自  https://newsn.net/say/xhprof-123.html



php性能分析利器xhprof扩展安装(php7.2.0b3)
发布于2017年10月07日    作者:苏南大叔    来源:程序如此灵动~
如果本文对您有帮助,或者节约了您的时间,欢迎打赏瓶饮料,建立下友谊关系。
本博客不欢迎:各种镜像采集行为。请尊重原创文章内容,转载请保留链接信息。
书接上回,苏南大叔在php5.6下安装了xhprof。换成了php7.2.0b3环境下,原版的xhprof0.9.4能编译,但是不能正常加载,提示phpapi不匹配。本文中,苏南大叔就向大家介绍一下,php7.2.0b3环境下,xhprof 的编译及加载。

第三方出品xhprof扩展
在github上面有2个php7下的相关xhprof扩展repoistry,分别是:

https://github.com/longxinH/xhprof
https://github.com/yaoguais/phpng-xhprof
都不是官方的出品的,是第三方出品。看上去前者longxinH/xhprof 更加接近原版,而且更好些,但是在苏南大叔的php7.2下面编译失败。后者yaoguais/phpng-xhprof 顺利编译通过,并顺利加载。但是后者看起来和原版的差距较大。

下载源码并解压
本文中,苏南大叔讲述下面这个版本的代码安装:

https://github.com/yaoguais/phpng-xhprof
这个源码解压完毕后,和原来的目录结构是不一样的。根目录可以理解为原版的extension目录。


php性能分析利器xhprof扩展安装(php7.2.0b3) (图4-1)
编译源码
Bash
phpize
./configure
make clean && make && sudo make install #没有make test
生成的so文件名和原来的不一样,叫做phpng_xhprof.so。


php性能分析利器xhprof扩展安装(php7.2.0b3) (图4-2)
修改php.ini


php性能分析利器xhprof扩展安装(php7.2.0b3) (图4-3)
[xhprof]
extension = phpng_xhprof.so
xhprof.output_dir = /tmp/xhprof
AD:PHP高手都在这里,就差你了

php性能分析利器xhprof扩展安装(php7.2.0b3) (图4-4)

新的xhprof版本号为0.9.5。
总结
欢迎继续关注苏南大叔的后续xhprof文章。https://newsn.net/tag/xhprof/

  【php】秘籍文章入口,仅传授于有缘之人  php    pecl

欢迎转载传播本篇原创文章,转载请保留链接及作者信息。
本站采用创作共用版权协议, 要求署名、非商业用途和相同方式共享。 
转载本站内容必须也遵循“署名-非商业用途-相同方式共享”的创作共用协议。
《程序如此灵动~》下所有原创文章,如被用于商业用途,请您按规定支付稿费。
苏南大叔需要你的支持
打赏任意金额,发送截图到邮箱 shang@newsn.net ,可以领取精选回馈如下(任选其一):
《前端视频教程大礼包》一套
《wordpress精选皮肤》一套
《dedecms织梦精选模板》一套
感谢您的打赏,让我更有动力,将更多精彩教程文章,呈现给大家!谢谢!


转载请注明来源:
作者:苏南大叔
原文:https://newsn.net/say/php7-xhprof-install.html


来自  https://newsn.net/say/php7-xhprof-install.html


Linux下PHP7使用xhprof分析性能


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lvchengbo/article/details/52849179

PECL(http://pecl.php.net/package/xhprof)上提供的最新扩展并不支持php7版本。

如果想为php7使用xhprof进行性能分析的话请参考https://github.com/Yaoguais/phpng-xhprof所介绍的方法进行编译安装。


Installation

  1. git clone git@github.com:Yaoguais/phpng-xhprof.git ./xhprof
  2. cd xhprof
  3. phpize
  4. ./configure
  5. make clean && make && make test && sudo make install


Then add the configuration into php.ini

  1. [xhprof]
  2. extension = phpng_xhprof.so
  3. xhprof.output_dir = /tmp/xhprof

If you compiled PHP7 from source code, then

  1. git clone git@github.com:Yaoguais/phpng-xhprof.git ./xhprof
  2. cd xhprof
  3. /path/to/php7/bin/phpize
  4. ./configure --with-php-config=/path/to/php7/bin/php-config
  5. make clean && make && make test && sudo make install

Then add the profile code

  1. xhprof_enable();
  2. // your code
  3. // ...
  4. file_put_contents((ini_get('xhprof.output_dir') ? : '/tmp') . '/' . uniqid() . '.xhprof.xhprof', serialize(xhprof_disable()));

Test

There are 12 test cases, the extension by 11,and the rest can not be due to the result of the PHP core,which is call_user_function family of functions.

You can use "make test" command to test the extension,and there are also simple test examples.

  1. /path/to/php7/bin/php diff/enable.php
  2. ls -l diff

Notice

This extension replaces the PHP core, so when you use other extensions like xdebug or phpdbg,which might be impaired.

You should add the phpng-xhprof configuration options to the php.ini of the bottom,and this is due to PHP 's startup sequence resulting from extension.


来自 https://blog.csdn.net/lvchengbo/article/details/52849179


PHP5.4安装xhprof扩展

Posted on 2013-01-31 20:50 张贺 阅读(4107) 评论(0编辑 收藏

PHP5.3或之前版本可以去pecl(http://pecl.php.net)下载xhprof扩展安装。

但pecl上的版本不支持PHP5.4

可以到github上的xhprof库中下载:https://github.com/facebook/xhprof

下载后进行解压安装

1 cd xhprof-master/extension/
2 phpize
3 ./configure --enable-xhprof
4 make
5 sudo make install

更改php.ini

1 [xhprof]
2 extension=xhprof.so
3 xhprof.output_dir="/document/gbyukg/www/test/xhprof"

重新启动apache。

简单使用:

复制代码
1 // start profiling
2 xhprof_enable();
3 
4 // run program
5 ......
6 
7 // stop profiler
8 $xhprof_data = xhprof_disable();
复制代码

xhprof_enable()允许接收一些参数,默认情况下,只会统计方法的调用次数和消耗的时间,通过传递参数(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY)打开统计CPU和内存使用率(在实际生产环境中会好关闭CPU统计信息,因为它会占用很多资源),同样也可以通过传递XHPROF_FLAGS_NO_BUILTINS参数来禁用对PHP内置函数的统计,甚至通过传递第二个参数来禁用对指定函数的统计,如:

1 // ignore builtin functions and call_user_func* during profiling
2 $ignore = array('call_user_func', 'call_user_func_array');
3 xhprof_enable(0, array('ignored_functions' =>  $ignore));

xhprof界面工具
页面工具存储在源代码目录中的xhprof_html文件夹下,同时需要xhprof_lib文件夹下的库文件。将这2个文件夹放到php.ini文件中指定的报告生成的目录中(应当是web服务器目录中)。
创建头和尾文件:

1 <?php
2 if (extension_loaded('xhprof')) {
3     include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_lib.php';
4     include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_runs.php';
5     xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
6 }

 

复制代码
 1 if (extension_loaded('xhprof')) {
 2     $profiler_namespace = 'myapp';  // namespace for your application
 3     $xhprof_data = xhprof_disable();
 4     $xhprof_runs = new XHProfRuns_Default();
 5     $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
 6  
 7     // url to the XHProf UI libraries (change the host name and path)
 8     $profiler_url = sprintf('http://myhost.com/xhprof/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace);
 9     echo '<a href="'. $profiler_url .'" target="_blank">Profiler output</a>';
10 }
复制代码

 

最后配置.htaccess文件使之自动调用上述2个文件

1 php_value auto_prepend_file /document/gbyukg/www/xhprof/header.php
2 php_value auto_append_file /document/gbyukg/www/xhprof/footer.php

 

 之后访问xhprof_html目录下的index.php文件

复制代码
// start profiling
xhprof_enable();
//profile CPU time and/or memory usage
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

// run program
......

// stop profiler
$xhprof_data = xhprof_disable();
复制代码
复制代码
 1 // start profiling
 2 xhprof_enable();
 3 
 4 // run program
 5 ....
 6 
 7 // stop profiler
 8 $xhprof_data = xhprof_disable();
 9 
10 //
11 // Saving the XHProf run
12 // using the default implementation of iXHProfRuns.
13 //
14 include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
15 include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
16 
17 $xhprof_runs = new XHProfRuns_Default();
18 
19 // Save the run under a namespace "xhprof_foo".
20 //
21 // **NOTE**:
22 // By default save_run() will automatically generate a unique
23 // run id for you. [You can override that behavior by passing
24 // a run id (optional arg) to the save_run() method instead.]
25 //
26 $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
复制代码

在生成的统计表格中,可以按照各个统计列进行排序,如:
Number of Calls:方法的调用次数
Memory Usage:内存占用率
Peak Memory Usage:内存峰值
CUP Time:CPU占用时间(包括内核使用时间和用户代码调用时间)
Wall Time:执行时间(如果执行一个远程调用,会包括CPU访问远程服务器、解析响应以及等待响应的时间和其它一些资源所占用的时间)

内存占用情况和CPU使用时间更进一步的分为Inclusive和Exclusive
Inclusive Time 包含该方法自己所占用的时间和该方法的所有子孙方法所占用的总资源或时间
Exclusive Time 仅仅包含该方法本身所占用的资源或时间


使用图形界面

可以通过点击页面上方的View Full Callgraph链接打开生成的图像模型,注意,在使用此功能前,请确保系统已经安装过GraphViz,Ubunt中可通过下面命令进行安装:

1 apt-get install graphviz

 当需要对当前项目进行优化时,我们首先需要对CPU进行排序,找出CPU占用时间最多的方法进行优化,之后按照优化内存使用率进行排序,对内存使用率最高的方法进行优化,接着按照wall time进行排序优化。

差别与统计报告

XHProf允许你对两次统计结果进行对比,对比方式是:

1 http://%xhprof-ui-address%/index.php?run1=XXX&amp;run2=YYY&amp;source=myapp

 

XXX和YYY是run id,myapp是命名空间,即save_run的第二个参数

同样也可以经多次生成的统计结果合并到一起生成一个统计报告:

1 http://%xhprof-ui-address%/index.php?run=XXX,YYY,ZZZ&amp;source=myapp

 


提示:
在对项目进行优化时,首先需要知道哪些地方需要优化,例如,项目中使用Zend Framewor,首先需要知道运行ZF框架所需要的资源以及时间,如果ZF运行时需要占用2.5M内存,那么不可能要让整个项目的内存占用小于2.5M。
同时并不需要每次运行都生成统计报告,可修改头问文件使之运行1000次生成一次报告。

header.php

复制代码
1 $xhprof_on = false;
2 if (mt_rand(1, 10000) === 1) {
3     $xhprof_on = true;
4     if (extension_loaded('xhprof')) {
5         include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_lib.php';
6         include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_runs.php';
7         xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
8     }
9 }
复制代码

 

footer.php

复制代码
 1 if ($xhprof_on && extension_loaded('xhprof')) {
 2     $profiler_namespace = 'myapp';  // namespace for your application
 3     $xhprof_data = xhprof_disable();
 4     $xhprof_runs = new XHProfRuns_Default();
 5     $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
 6  
 7     // url to the XHProf UI libraries (change the host name and path)
 8     $profiler_url = sprintf('http://myhost.com/xhprof/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace);
 9     echo '<a href="'.$profiler_url.'" target="_blank">Profiler output</a>';
10 }
复制代码

 

 来自  https://www.cnblogs.com/gbyukg/archive/2013/01/31/2888183.html




xhprof扩展的安装和简单使用

版权声明:本文为博主原创文章,未经博主允许不得转载。https://blog.csdn.net/liuzp111/article/details/51474197

查看是否是否安装xhprof扩展


php --ri xhprof #检查php是否有这个扩展

1

xhprof扩展的安装

wget http://pecl.php.net/get/xhprof-0.9.4.tgz

tar zxvf xhprof-0.9.4.tgz 

cd xhprof-0.9.4

whereis phpize

/usr/bin/phpize

1

2

3

4

5

执行到这里报错了,错误信息如下:


[root@fengniu020 xhprof-0.9.4]# /usr/bin/phpize

Cannot find config.m4. 

Make sure that you run '/usr/bin/phpize' in the top level source directory of the module


[root@fengniu020 xhprof-0.9.4]# 

1

2

3

4

5

咋办呢? 

参考:安装PHP扩展 xhprof 报错 Cannot find config.m4 的解决办法


[root@fengniu020 xhprof-0.9.4]# /usr/bin/phpize

Cannot find config.m4. 

Make sure that you run '/usr/bin/phpize' in the top level source directory of the module


[root@fengniu020 xhprof-0.9.4]# l

-bash: l: command not found

[root@fengniu020 xhprof-0.9.4]# ls

CHANGELOG  examples   LICENSE  xhprof_html

CREDITS    extension  README   xhprof_lib

[root@fengniu020 xhprof-0.9.4]# cd extension/

[root@fengniu020 extension]# ls

config.m4  php_xhprof.h  tests  xhprof.c

[root@fengniu020 extension]# phpize

Configuring for:

PHP Api Version:         20100412

Zend Module Api No:      20100525

Zend Extension Api No:   220100525

[root@fengniu020 extension]# 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

解决了安装错误,继续安装


 whereis php-config#查找php-config的位置

 ./configure --with-php-config=/usr/bin/php-config 

 make && make install 

 vim /etc/php.ini 

1

2

3

4

在php.ini中加入此扩展


extension = xhprof.so

1

重启php-fpm生效


service php-fpm restart

1

在脚本中开始处使用xhprof_enable()开启 

在脚本之后使用 $data = xhprof_disable() 返回数据


运行下xhprof,试试效果,可能可以正常运行不:


我的xhprof安装目录是在:


/hotdata/soft

1

现在建立个测试目录,并有一个域名指向到/hotdata/kehu/wk


/hotdata/kehu/wk/ddd/

1

把安装目录的文件夹拷贝到测试目录下


 cp -Rf ./xhprof-0.9.4  /hotdata/kehu/wk/ddd/

 mv xhprof-0.9.4 xhprof

1

2

在浏览器上运行官方提供的例子


http://wk.baidu.com/ddd/xhprof/examples/sample.php

1

可以看到有如下结果 

 

第一种方式:复制上面到运行的结果(http路径),再次放入浏览器,填好前面对应的域名:


http://wk.baidu.com/ddd/xhprof/xhprof_html/index.php?run=5741289a6ccef&source=xhprof_foo

1

可以看到结果: 


第二种方式: 

直接访问


http://wk.baidu.com/ddd/xhprof/xhprof_html/index.php

1

这里会展示检测到运行过的id 



如果查看图形化展示 

报错了:


failed to execute cmd:" dot -Tpng". stderr:`sh: dot:command not found`

1

解决办法:


yum install graphviz

1

再点击就可以看到图形化展示了 

 

可参考这个链接,写的很不错: 

XHProf的安装和使用(PHP性能测试神器)


PHP官网链接: 

http://php.net/manual/zh/intro.xhprof.php


facebook文档: 

http://web.archive.org/web/20110514095512/http://mirror.facebook.net/facebook/xhprof/doc.html

--------------------- 

作者:Everything1209 

来源:CSDN 

原文:https://blog.csdn.net/everything1209/article/details/51474197 

版权声明:本文为博主原创文章,转载请附上博文链接!



版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuzp111/article/details/51474197

查看是否是否安装xhprof扩展

php --ri xhprof #检查php是否有这个扩展
  • 1

xhprof扩展的安装

wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar zxvf xhprof-0.9.4.tgz 
cd xhprof-0.9.4
whereis phpize
/usr/bin/phpize
  • 1

  • 2

  • 3

  • 4

  • 5

执行到这里报错了,错误信息如下:

[root@fengniu020 xhprof-0.9.4]# /usr/bin/phpize
Cannot find config.m4. 
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module

[root@fengniu020 xhprof-0.9.4]# 
  • 1

  • 2

  • 3

  • 4

  • 5

咋办呢? 
参考:安装PHP扩展 xhprof 报错 Cannot find config.m4 的解决办法

[root@fengniu020 xhprof-0.9.4]# /usr/bin/phpize
Cannot find config.m4. 
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module

[root@fengniu020 xhprof-0.9.4]# l
-bash: l: command not found
[root@fengniu020 xhprof-0.9.4]# ls
CHANGELOG  examples   LICENSE  xhprof_html
CREDITS    extension  README   xhprof_lib
[root@fengniu020 xhprof-0.9.4]# cd extension/
[root@fengniu020 extension]# ls
config.m4  php_xhprof.h  tests  xhprof.c
[root@fengniu020 extension]# phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@fengniu020 extension]# 
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

解决了安装错误,继续安装

 whereis php-config#查找php-config的位置
 ./configure --with-php-config=/usr/bin/php-config 
 make && make install 
 vim /etc/php.ini 
  • 1

  • 2

  • 3

  • 4

在php.ini中加入此扩展

extension = xhprof.so
  • 1

重启php-fpm生效

service php-fpm restart
  • 1

在脚本中开始处使用xhprof_enable()开启 
在脚本之后使用 $data = xhprof_disable() 返回数据

运行下xhprof,试试效果,可能可以正常运行不:

我的xhprof安装目录是在:

/hotdata/soft
  • 1

现在建立个测试目录,并有一个域名指向到/hotdata/kehu/wk

/hotdata/kehu/wk/ddd/
  • 1

把安装目录的文件夹拷贝到测试目录下

 cp -Rf ./xhprof-0.9.4  /hotdata/kehu/wk/ddd/
 mv xhprof-0.9.4 xhprof
  • 1

  • 2

在浏览器上运行官方提供的例子

http://wk.baidu.com/ddd/xhprof/examples/sample.php
  • 1

可以看到有如下结果 
这里写图片描述 
第一种方式:复制上面到运行的结果(http路径),再次放入浏览器,填好前面对应的域名:

http://wk.baidu.com/ddd/xhprof/xhprof_html/index.php?run=5741289a6ccef&source=xhprof_foo
  • 1

可以看到结果: 
这里写图片描述
第二种方式: 
直接访问

http://wk.baidu.com/ddd/xhprof/xhprof_html/index.php
  • 1

这里会展示检测到运行过的id 
这里写图片描述

如果查看图形化展示 
报错了:

failed to execute cmd:" dot -Tpng". stderr:`sh: dot:command not found`
  • 1

解决办法:

yum install graphviz
  • 1

再点击就可以看到图形化展示了 
这里写图片描述 
可参考这个链接,写的很不错: 
XHProf的安装和使用(PHP性能测试神器)

PHP官网链接: 
http://php.net/manual/zh/intro.xhprof.php

facebook文档: 
http://web.archive.org/web/20110514095512/http://mirror.facebook.net/facebook/xhprof/doc.html





https://blog.csdn.net/lvchengbo/article/details/52849179


普通分类: