mac系统PHP 7.1.12安装xhprof并使用[View Full Callgraph]小记
前几天从php7.0.x 升级到了php7.2.0版本, 结果装xhprof没有找到能支持对应版本的xhprof
于是又安装了一个php7.1.2的版本(brew install h)
接着安装xhprof扩展
git clone https://github.com/longxinH/xhprof
cd xhprof/extension/
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin//php-config
make && sudo make install
启用扩展
vim /usr/local/etc/php/7.1/php.in 最后引入扩展,并自定义输出目录
[xhprof]
extension = xhprof.so
xhprof.output_dir = /Users/liugx/work/php/xhprof
将 上面下载的 xhprof 文件夹中的这两个目录复制一份到 /Users/liugx/work/php/xhprof 目录下
cd ..
cp -r xhprof_lib/ /Users/liugx/work/php/xhprof/xhprof_lib/
cp -r xhprof_html/ /Users/liugx/work/php/xhprof/xhprof_html/
并在/Users/liugx/work/php/xhprof根目录下添加文件 inject.php,如下:
<?php
/**
* User: szliugx@gmail.com
* Date: 17/12/20
* Time: 上午11:32
*/ //开启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数据
$XHPROF_ROOT = '/Users/liugx/work/php/xhprof';
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
echo $run_id;
});
将 /Users/liugx/work/php/xhprof 目录设置称web站点,监控站点nginx配置
server {
listen ;
server_name xhprof-view.com;
#root /Users/liugx/work/php/xhprof;
location / {
root /Users/liugx/work/php/xhprof;
#try_files $uri $uri/ /index.php?$query_string;
index index.php index.html index.htm;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ \.php$ {
root /Users/liugx/work/php/xhprof;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PHP_VALUE "auto_prepend_file=/Users/liugx/work/php/xhprof/inject.php"; #(此配置文件中不用加,需要监控哪个站点加上这一行就行)
include fastcgi_params;
}
}
### ⚠ 这样监控站点和被监控站点的配置(被监控站点nginx配置只需要加一行代码
fastcgi_param PHP_VALUE "auto_prepend_file=/Users/liugx/work/php/xhprof/inject.php";
)就完了,重启php-fpm和nginx,访问被监控站点,访问http://xhprof-view.com/xhprof_html/ 就能得到一些监控信息列表,如下:

然后点击一条详情,输出如下:

展示详细的硬件消耗和时间消耗信息,如果想更直观的看,可以已图片的形式看调用过程情况,点击页面中的 [View Full Callgraph]

红色区域就是耗时最多的地方,但是这个功能需要安装 Graphviz
一开始准备直接 brew install graphviz,结果失败了,因为安装时,里面有个依赖webp是Google的源
于是上http://graphviz.org/download/官网,介绍还可以MacPorts 方式安装,这次安装成功了
先下载安装MacPorts,找到系统对应的版本
http://distfiles.macports.org/MacPorts/MacPorts-2.4.0-10.10-Yosemite.pkg
下载安装完后,终端执行
sudo port -v selfupdate
sudo port install graphviz
安装完后,如下说明安装成功并且执行文件已经加入了环境变量
liugx@liugx ~$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)
这时,如果点击[View Full Callgraph]如果还是出现,mac sh: dot: command not found 这样的信息,直接改/Users/liugx/work/php/xhprof/xhprof_lib/utils/callgraph_utils.php
中的
$cmd = " dot -T".$type; 改成 $cmd = " /opt/local/bin/dot -T".$type; 相当于给了绝对路径,不怕找错地方(此方法不推荐)
我是直接建了个链接从原文件到目标文件
ln /opt/local/bin/dot /usr/local/bin/dot
mac系统PHP 7.1.12安装xhprof并使用[View Full Callgraph]小记的更多相关文章
- Mac系统下使用VirtualBox虚拟机安装win7--第一步 安装vbox虚拟机
Mac系统下使用VirtualBox虚拟机安装win7操作步骤: 第一步 安装vbox虚拟机 1.先下载vbox,下载地址:: https://www.virtualbox.org/wiki/Down ...
- Mac系统下使用VirtualBox虚拟机安装win7--第五步 共享文件夹设置
1.启动virtualbox--选中win7虚拟机--点击设置--点击共享文件夹--点击右侧按钮添加共享文件夹
- Mac系统下使用VirtualBox虚拟机安装win7--第三步 在虚拟机上安装 Windows 7
第三步 在虚拟机上安装 Windows 7 等待虚拟机进入 Windows 7 的安装界面以后,在语言,货币,键盘输入法这一面,建议保持默认设置,直接点击“下一步”按钮,如图所示
- Mac系统下使用VirtualBox虚拟机安装win7--第四步 安装虚拟机硬件扩展包支持
如 果想要在虚拟机上使用连接在 Mac 上的硬件外设,比如 U 盘,iPhone 等,需要我们在 Virtual Box 官网下载一个硬件支持扩展安装包.同样地,我们先打开虚拟机的下载页面: http ...
- Mac系统下使用VirtualBox虚拟机安装win7--第二步 创建win7系统
第二步 创建win7系统 启动 Virtual Box 以后,点击窗口左上角的“新建”按钮,如图所示
- Mac系统下源码编译安装MySQL 5.7.17
1.下载并解压到:/Users/xiechunping/Softwares/mysql-5.7.17下载地址:http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MyS ...
- [视频]mac系统下虚拟机parallels安装ubuntu 14.04视频教程
此文是http://www.mr-wu.cn/install-ubuntu-14-04-on-parallels-for-mac/这篇博文的补充,为整个ubuntu 14.04安装过程的视频录像. m ...
- mac系统下虚拟机parallels安装ubuntu 14.04
mac系统很棒,mac下的开发环境也很棒,但有时你还得需要ubuntu开发环境,比如进行嵌入式Linux交叉编译,使用Linaro toolchain… 其实mac系统下使用parallels虚拟机安 ...
- Windows和Mac系统下安装Docker
在windows和mac系统中使用Docker Desktop安装Docker对系统的要求是很高的. 对于 Windows 系统来说,安装 Docker for Windows 需要符合以下条件: 必 ...
随机推荐
- day5-re模块
一.概述 但凡有过语言开发经验的童鞋都清楚,很多时候需要进行字符串的匹配搜索.查找替换等处理,此时正则表达式就是解决问题的不二法门.正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强 ...
- 2.spring cloud eureka client配置
红色加粗内容表示修改部分 1.把server项目打成jar包并启动 在项目根目录cmd执行 mvn clean package -Dmaven.test.skip=true mavne仓库地址建议 ...
- ssh自动分发密匙脚本样板
#!/bin/bash rom=/media/cdrom dir=/etc/yum.repos.d Use=$ mima=$ function yumj(){ [ -d "$rom" ...
- MySQL简单的操作,增删改查
B/S架构模式与C/S架构模式的区别 B/S=WEB/SERVER C/S=CLIENT/SERVIR B/S:用户通过web浏览器打开域名就能访问服务器server的方式就叫做B/S用户不需要安装任 ...
- GSpan-频繁子图挖掘算法
GSpan频繁子图挖掘算法,网上有很多相关的介绍,中文的一些资料总是似是而非,讲的不是很清楚(感觉都是互相抄来抄去,,,基本都是一个样,,,),仔细的研读了原论文后,在这里做一个总结. 1. GSpa ...
- LeetCode OJ:Number of Islands(孤岛计数)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- pdi vcard-2.1
vCard The Electronic Business Card Version 2.1 A versit Consortium Specification September 18, 1996 ...
- MATROSKA 文件格式
MATROSKA 文件格式 1.EBML (Extensible Binary Meta Language): EBML语言使用不定长整数,这种方式相对于固定长度的32位/64位字长的整数值更节约空间 ...
- keras系列︱seq2seq系列相关实现与案例(feedback、peek、attention类型)
之前在看<Semi-supervised Sequence Learning>这篇文章的时候对seq2seq半监督的方式做文本分类的方式产生了一定兴趣,于是开始简单研究了seq2seq.先 ...
- Xcode 9 俩个你必须知道的新功能
Xcode 9 beta 版已经可以下载了,不知道大家伙对这个新版本开发工具看法如何,最近我费了一番周折终于体验了一把,升级系统,下载Xcode,验证安装扒拉扒拉什么的,几乎搞了我一天,我做开发使用的 ...