使用PHP扩展Xhprof分析项目性能实践

1、背景

项目即将上线,想经过一些工具来分析代码的稳定性和效率,想起在上个团队时使用过的xhprof扩展;由于换了新电脑,因此须要从新编译此扩展,现将安装与实际排查过程完整记录下来,方便本身回顾和帮助更多的读者。php

2、操做步骤

  1. 安装扩展
  2. 配置扩展
  3. 测试分析

3、安装

xhprof扩展PHP并不自带,须要笔者去单独安装它,安装以后才能使用,笔者这里采用源码安装方式,安装过程以下git

3.1 下载源码

xhprof在PHP的PECL官方上面已经比较老了,笔者的PHP版本为PHP7.1所以,须要在GitHub上下载xhprof上比较新的源码,参考命令以下github

git clone https://github.com/longxinH/xhprof

3.2 检测环境

进入编译的文件夹,参考命令app

cd xhprof/extension/

如今笔者须要编译一下源码,在编译以前可使用phpze来探测PHP的环境,参考命令以下:工具

phpize

返回结果以下测试

Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

3.3 编译安装

生成 Makefile,为下一步的编译作准备ui

./configure

返回结果以下spa

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged

开始编译,并进行安装code

make && make install

返回结果以下get

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/Cellar/php@7.1/7.1.19/pecl/20160303/

从返回信息中能够看到已经安装完成,并显示了扩展文件存放的位置

4、配置

在编译安装源码以后,笔者还须要对PHP的配置文件夹以及xhprof的进行一些简单的配置,操做过程以下所示

相关文章
相关标签/搜索