---
title: "php程序性能分析工具"
author: "phpseyo"
date: "2014-02-20T11:40:55Z"
tags: []
categories: ["编程语言"]
slug: "php"
draft: false
lastmod: "2014-02-20T11:42:40Z"
id: 2019656
url: "https://phpseyo.iteye.com/blog/2019656"
---

平常开发一些效率要求比较高的功能模块时，常常需要分析程序的运行瓶颈在哪。用下面这个工具可以很方便的查看PHP的脚本执行过程。下面是配置步骤：

1\. PHP安装XDEBUG，网上很多教程，下面贴上php.ini中的配置项

\[xdebug]

zend\_extension=/usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so

 

xdebug.profiler\_output\_dir="/mnt/hgfs/web/log/xdebug"

xdebug.profiler\_output\_name = "cachegrind.out.%t-%s"

xdebug.remote\_autostart = On

xdebug.remote\_enable = On

xdebug.profiler\_enable\_trigger=1

xdebug.remote\_host="127.0.0.1"

xdebug.remote\_port=9000

xdebug.remote\_handler="dbgp"

xdebug.remote\_mode=req

 

这样配置后，平常执行php程序并不会生成性能调试文件，只有在url的后缀加上url参数 XDEBUG\_PROFILE=1 才会生成调试文件。调试文件在 xdebug.profiler\_output\_dir 这个参数配置的路径中。

 

2\. 安装解析调试文件的工具 qcachegrind

 下载地址：http://sourceforge.net/projects/qcachegrindwin/

打开 qcachegrind，选择前面生成的调试文件打开即可查看。

其实有好几个这种类型的工具，这个是我用过觉得比较直接明了的。

 

![](http://dl2.iteye.com/upload/attachment/0094/0285/007a16ca-46aa-3c98-ae13-94437703723c.gif)