选择一个工具分析PHP函数调用的资源耗用明细,以图表化的形式展现,方便优化代码。

安装xhprof

$ pecl install xhprof-beta

在php.ini引用的extension中添加extension=xhprof.so

GUI

这里选择了xhgui,它的原理是在需要测试性能的脚本前加上PHP的一段代码,将收集到的性能数据存储到文件或者mongodb等存储介质中去。

MongoDB

$ apt-get install mongodb


前端


cd /var/www

git clone https://github.com/perftools/xhgui.git

cd xhgui

php install.php
  • 如果不能以root身份运行,那么sudo -u www-data php install.php


  • 安装的时候出现
the requested PHP extension mongodb is missing from your system
问题是平台的拓展名为mongo.so,而composer检查的是mongodb.so,只要加上--ignore-platform-reqs


  • 如果composer问题不清楚,建议单独跑composer命令,加上-vvv打开调试模式

使用

如前面说的原理是在头部添加一段PHP代码,这里通过在Nginx里配置,或者PHP ini auto_prepend_file
在php.ini中添加auto_prepend_file
。

location ~ \.php {

include fastcgi_params;

fastcgi_buffers 128 4k;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "auto_prepend_file=\"/opt/htdocs/xhgui/external/header.php\"";
}

配置

在config目录下添加config.php配置

<?php
return array(
'debug' => false,
'mode' => 'development', // Can be either mongodb or file.
/*
'save.handler' => 'file',
'save.handler.filename' => dirname(__DIR__) . '/cache/' . 'xhgui.data.' . microtime(true) . '_' . substr(md5($url), 0, 6),
*/
'save.handler' => 'mongodb', // Needed for file save handler. Beware of file locking. You can adujst this file path
// to reduce locking problems (eg uniqid, time ...)
//'save.handler.filename' => __DIR__.'/../data/xhgui_'.date('Ymd').'.dat',
'db.host' => '127.0.0.1:27017',
'db.db' => 'xhprof', // Allows you to pass additional options like replicaSet to MongoClient.
// 'username', 'password' and 'db' (where the user is added)
'db.options' => array(),
'templates.path' => dirname(__DIR__) . '/src/templates',
'date.format' => 'M jS H:i:s',
'detail.count' => 6,
'page.limit' => 25, // Profile 1 in 100 requests.
// You can return true to profile every request.
'profiler.enable' => function() {
return rand(1, 100) === 3;
}, 'profiler.simple_url' => function($url) {
return preg_replace('/\=\d+/', '', $url);
} );

xhprof安装记录的更多相关文章

  1. PHP性能检测与优化—XHProf 安装

    PHP性能检测与优化—XHProf 安装 XHProf是facebook开源出来的一个php轻量级的性能分析工具,跟Xdebug类似,但性能开销更低,还可以用在生产环境中,也可以由程序开关来控制是否进 ...

  2. 分布式监控系统Zabbix-3.0.3-完整安装记录(7)-使用percona监控MySQL

    前面已经介绍了分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控,但是没有提供可以直接使用的Key,太过简陋,监控效果不佳.要想更加仔细的监控Mysql,业内同学们都会选择 ...

  3. 关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用

    关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用   工作环境:window下 在一切的最开始,安装node.js (中文站,更新比较慢http://nodejs.cn/) ...

  4. PHP性能优化工具–xhprof安装

    PHP性能优化工具–xhprof安装,这里我先贴出大致的步骤: 1.获取xhprof 2.编译前预处理 3.编译安装 4.配置php.ini 5.查看运行结果 那么下面我们开始安装xhprof工具吧: ...

  5. sourceinsight安装记录

    sourceinsight安装记录 此文章为本人使用sourceinsight一个星期之后的相关设置步骤记录和经验记录,以备以后查验,网上的相关资料都也较为完善,但是对于新手还是有一定困难的,所以在这 ...

  6. openerp安装记录及postgresql数据库问题解决

    ubuntu-14.04下openerp安装记录1.安装PostgreSQL 数据库    a.安装         sudo apt-get install postgresql    安装后ubu ...

  7. Matlab安装记录 - LED Control Activex控件安装

    Matlab安装记录-LED Control Activex控件安装 2013-12-01  22:06:36 最近在研究Matlab GUI技术,准备用于制作上位机程序:在Matlab GUI的技术 ...

  8. Arch Linux 安装记录

    Arch Linux 安装记录 基本上参考wiki上的新手指南,使用arch 2014.6.1 iso安装 设置网络 有线网络 Arch Linux 默认开启DHCP. 静态ip 首先关闭DHCP:s ...

  9. redis5.0.3单实例简单安装记录

    redis5.0.3单实例简单安装记录 日常需要测试使用,索性记录下来,免得临时又麻烦的找资料. yum -y install make gcc-c++ cmake bison-devel ncurs ...

随机推荐

  1. codeforces 416B. Appleman and Tree 树形dp

    题目链接 Fill a DP table such as the following bottom-up: DP[v][0] = the number of ways that the subtree ...

  2. ngCookies模块

    Angular中ngCookies模块介绍 1.Cookie介绍 Cookie总是保存在客户端中,按在客户端中的存储位置,可分为内存Cookie和硬盘Cookie.内存Cookie由浏览器维护,保存在 ...

  3. Tensorflow tflearn 编写RCNN

    两周多的努力总算写出了RCNN的代码,这段代码非常有意思,并且还顺带复习了几个Tensorflow应用方面的知识点,故特此总结下,带大家分享下经验.理论方面,RCNN的理论教程颇多,这里我不在做详尽说 ...

  4. 求1~n直接1出现的次数

    参考前人的统计思想:分别统计个.十.百...亿等第N位上1出现的次数. 如ABCDE,在统计D位1出现的次数时,用D做分割符,ABC为Before,E为After. 分情况考虑:(n为D的length ...

  5. rsyslog 传输日志

    nginx 服务器: front-end:/usr/local/nginx/logs# cat /etc/rsyslog.conf | grep -v "^$" | grep -v ...

  6. 具有 CSA CCM 证明的 SOC 2 可简化 Windows Azure 客户的安全性评估过程

    编辑人员注释:本文章由 Windows Azure 产品市场营销总监 Sarah Fender 撰写. 今天,我们宣布 Microsoft 的公共审计师 Deloitte 已经发布了有关 Window ...

  7. HDU 5735 Born Slippy(拆值DP+位运算)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5735 [题目大意] 给出一棵树,树上每个节点都有一个权值w,w不超过216,树的根为1,从一个点往 ...

  8. 封装的localstorge的插件,store.js

    封装的localstorge的插件,store.js https://github.com/marcuswestin/store.js/

  9. 网页解析不了PHP源代码的解决方法

    一般出现这个错误都是因为修改了apache配置文件,但是没有使apache配置生效. 所以只要执行以下命令就行了: sudo apachectl restart sudo apachectl grac ...

  10. UVA - 297Quadtrees(四分图)

    Quadtrees Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Statu ...