Table of Contents
PHP性能分析工具XHProf安装使用教程,xhprof安装使用
xhprof test
Home php教程 php手册 PHP性能分析工具XHProf安装使用教程,xhprof安装使用

PHP性能分析工具XHProf安装使用教程,xhprof安装使用

Jun 13, 2016 am 09:04 AM
php stack tool Performance analysis

PHP性能分析工具XHProf安装使用教程,xhprof安装使用

HProf是facebook开源出来的一个php轻量级的性能分析工具,跟Xdebug类似,但性能开销更低,还可以用在生产环境中,也可以由程序开关来控制是否进行profile。基于浏览

器的性能分析用户界面能更容易查看,或是与同行们分享成果。也能绘制调用关系图。在数据收集阶段,它记录调用次数的追踪和包容性的指标弧在动态callgraph的一个程序。

它独有的数据计算的报告/后处理阶段。在数据收集时,XHProfd通过检测循环来处理递归的函数调用,并通过给递归调用中每个深度的调用一个有用的命名来避开死循环。

XHProf的轻量级性质和汇聚功能,使得它非常适合用于收集“生产环境”的性能统计数据的统计。

1. 安装XHProf
复制代码 代码如下:
wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar zxf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib
cd extension
phpize
./configure
make
make install

2. 配置 php.ini 文件
复制代码 代码如下:
[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
; 记得WEB要有写入权限
xhprof.output_dir=

重启服务让修改生效,现在就可以使用XHProf了,不过为了显示效果更炫,最好继续安装Graphviz。

3. 安装Graphviz
复制代码 代码如下:
wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz  
tar zxf graphviz-2.26.3.tar.gz   
cd graphviz-2.26.3  
./configure
make   
make install

安装完成后,会生成/usr/local/bin/dot文件,你应该确保路径在PATH环境变量里,以便XHProf能找到它。

4. 应用XHProf

复制代码 代码如下:
xhprof_enable();//打开xhprof

/******程序逻辑 Start******/
function test1(){
 sleep(3);
 return;
}
function test2(){
 test1();
}
function test3(){
 test2();
}
function p(){
 echo '

xhprof test

';
}
p();
test3();
/******程序逻辑 End******/

$xhprof_data = xhprof_disable();//关闭xhprof

//保存xhprof数据
include_once '../xhprof_lib/utils/xhprof_lib.php';
include_once '../xhprof_lib/utils/xhprof_runs.php';

$xhprof_runs = new XHProfRuns_Default();
$xhprof_source = 'xhprof_test';
$run_id = $xhprof_runs->save_run($xhprof_data, $xhprof_source);
$report_url = 'http://xhprof.rebill.info/index.php?run='.$run_id.'&source='.$xhprof_source;
echo '
';
echo 'view the performance report:'.$report_url.'';

如此一来,会在上面设定的xhprof.output_dir目录里生成名字类似4c236583ef490.xhprof_test的数据文件,可以很方便的通过Web方式浏览效果:
http://xhprof.rebill.info/index.php?run=4c236583ef490&source=xhprof_test

目前显示的是表格形式的显示,点击页面上的[View Full Callgraph],就能看到精美的图片显示了。

在线测试体验地址:http://xhprof.rebill.info/test.php

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to manually trigger the onBlur event of a cell in Avue-crud row editing mode? How to manually trigger the onBlur event of a cell in Avue-crud row editing mode? Apr 04, 2025 pm 02:00 PM

The onBlur event that implements Avue-crud row editing in the Avue component library manually triggers the Avue-crud component. It provides convenient in-line editing functions, but sometimes we need to...

How to quickly build a foreground page in a React Vite project using AI tools? How to quickly build a foreground page in a React Vite project using AI tools? Apr 04, 2025 pm 01:45 PM

How to quickly build a front-end page in back-end development? As a backend developer with three or four years of experience, he has mastered the basic JavaScript, CSS and HTML...

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use JavaScript plug-in to achieve the effect of page fixation and element independent movement? How to use JavaScript plug-in to achieve the effect of page fixation and element independent movement? Apr 04, 2025 pm 12:51 PM

Implementing the page fixing effect of independently moving scroll bars and elements In web design, sometimes we need to achieve a special effect, that is, when the scroll bars scroll...

How to create a React application with pnpm instead of npm? How to create a React application with pnpm instead of npm? Apr 04, 2025 pm 06:45 PM

About using pnpm instead of npm to create a React application using npx...

How to effectively modify and replay requested cookies in Chrome DevTools? How to effectively modify and replay requested cookies in Chrome DevTools? Apr 04, 2025 pm 05:48 PM

How to effectively modify and replay requested cookies in ChromeDevTools using Chrome...

See all articles