资讯详情

docker安装php xhprof扩展及使用方法

1. 进入php安装命令行模式xhprof扩展

# 1. 进入扩展文件目录 cd /usr/src/php/ext  # 2. 下载xhprof扩展包 # 注释:https://pecl.php.net/get/xhprof-2.3.5.tgz地址从https://pecl.php.net/package/xhprof选择最新的包复制地址(参考图1) wget https://pecl.php.net/get/xhprof-2.3.5.tgz # 如果没有wget先安装命令 yum install wget 或 apt-get install wget  # 3. 解压下载tgz压缩包 tar -zcvf xhprof-2.3.5.tgz  # 4. 复制文件夹extension到该目录 cp xhprof-2.3.5/extension ./  # 5. 将extension重命名为xhprof mv extension/ xhprof/  # 6. 安装该扩展 docker-php-ext-install xhprof  # 查看扩展,可以看到已经安装好了 php -v  

图一: 在这里插入图片描述

2. 开启xhprof扩展

# 1. 进入上一步xhprof执行文件夹make命令 make && make install # 2. 修改php.ini添加和扩展文件配置生成xhprof存储文件的位置 extension = "xhprof.so" xhprof.output_dir= /usr/local/... # 根据实际情况设置目录,默认为/tmp下 # 3. 重启php-fpm即可 

3. Yii2写法示例

//1. 在web.php添加以下内容  include_once "...你的实际路径.../xhprof-2.3.5/xhprof_lib/utils/xhprof_lib.php"; include_once "...你的实际路径.../xhprof-2.3.5/xhprof_lib/utils/xhprof_runs.php"; if (!function_exists('xhprof_start')) { 
             function xhprof_start() { 
                 xhprof_enable(XHPROF_FLAGS_CPU   XHPROF_FLAGS_MEMORY);     } } if (!function_exists('xhprof_end')) { 
             function xhprof_end($id, $action_id) { 
                 $xhprof_data = xhprof_disable();         $xhprof_runs = new \XHProfRuns_Default(); return $xhprof_runs->save_run($xhprof_data, $id . '-' . $action_id); } } //2. 在你想要分析的方法内加入以下内容 // 在方法最开始加入下面代码 xhprof_start(); // 在方法结尾加入下面代码,其中$this->id为控制器名,$this->action->id为方法名 $run_id = xhprof_end($this->id, $this->action->id); 

4. 配置访问xhprof文件方式

将xhprof-2.3.5文件夹放在nginx可访问的目录下,并配置网站根目录为xhprof-2.3.5下的xhprof_html。

配置好后访问路径为

// 其中$run_id为上一步中的$run_id,
// 自动创建的文件名(位置是在php.ini中设置的xhprof.output_dir= /usr/local/...这个)也会包含这个run_id,
// 其中$source为【$xhprof_runs->save_run($xhprof_data, $id . '-' . $action_id);】中的$id . '-' . $action_id
// 自动创建的文件名(位置是在php.ini中设置的xhprof.output_dir= /usr/local/...这个)也会包含这个$source,

http(s)://$domain/index.php?run=$run_id&source=$source

// 也可以直接访问
http(s)://$domain/index.php // 会列出所有xhprof文件

5. XHProf报告字段含义

:方法名称。

:方法被调用的次数。

:方法调用次数在同级方法总数调用次数中所占的百分比。

:方法执行花费的时间,包括子方法的执行时间。(单位:微秒)

:方法执行花费的时间百分比。

:方法本身执行花费的时间,不包括子方法的执行时间。(单位:微秒)

:方法本身执行花费的时间百分比。

:方法执行花费的CPU时间,包括子方法的执行时间。(单位:微秒)

:方法执行花费的CPU时间百分比。

:方法本身执行花费的CPU时间,不包括子方法的执行时间。(单位:微秒)

:方法本身执行花费的CPU时间百分比。

:方法执行占用的内存,包括子方法执行占用的内存。(单位:字节)

:方法执行占用的内存百分比。

:方法本身执行占用的内存,不包括子方法执行占用的内存。(单位:字节)

:方法本身执行占用的内存百分比。

:Incl.MemUse峰值。(单位:字节)

:Incl.MemUse峰值百分比。

:Excl.MemUse峰值。单位:(字节)

:Excl.MemUse峰值百分比。

标签: ecpu电容

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台