PHP执行慢分析工具xdebug + webgrind

首先要安装 php 扩展 xdebug,这里不做介绍

1
2
3
4
5
6
[xdebug]
zend_extension=xdebug.so
xdebug.trace_output_dir=/tmp/xdebug
xdebug.profiler_output_dir = /tmp/xdebug
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = 1

创建 xdebug 目录

1
2
mkdir  /tmp/xdebug
chown www:www /tmp/xdebug

webgrind 安装

1
git clone https://github.com/jokkedk/webgrind.git

配置虚拟主机,确保能访问到 webgrind 目录

配置 webgrind 的 config.php

1
2
static $storageDir = '/tmp/webgrind';
static $profilerDir = '/tmp/xdebug';

创建 webgrind 目录

1
2
mkdir /tmp/webgrind
chown www.www /tmp/webgrind

分析

选择要分析的文件,然后电机 update 即可

  • Invocation Count:函数调用次数
  • Total Self Cost:函数本身花费的时间
  • Total Inclusive Cost:包含内部函数花费的时间