设为首页
收藏本站
切换到宽版
用户名
Email
自动登录
找回密码
密码
登录
注册
快捷导航
论坛
BBS
排行榜
Ranklist
搜索
搜索
热搜:
香港vps
香港VPS
amh
机柜
vps
分销
VPS
域名出售
火车头
云主机
不限流量
香港服务器
美国服务器
香港
全能空间
whmcs
digitalocean
本版
帖子
用户
MJJ论坛
»
论坛
›
技术交流分享
›
Web技术
›
PHP执行慢分析工具xdebug + webgrind
返回列表
查看:
1521
|
回复:
0
PHP执行慢分析工具xdebug + webgrind
[复制链接]
土小帽
土小帽
当前离线
积分
4143
发表于 2023-11-3 22:12:06
|
显示全部楼层
|
阅读模式
经常碰到用户PHP网站打开速度慢,运维环境配置的锅?PHP代码的锅?当你发现程序变慢,但有时我们不知道具体是哪块代码执行慢(排除环境问题),或者哪个方法占用了太长的执行时间,这时我们就需要一个调试工具,来帮我们记录程序执行过程中的一些具体信息,包括类、方法名、执行时间、次数等信息,今天介绍的工具是xdebug以及他的结果分析展示工具webgrind。
xdebug安装
cd /root/oneinstack/src
wget https://xdebug.org/files/xdebug-2.5.5.tgz
tar xzf xdebug-2.5.5.tgz
cd xdebug-2.5.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
php加载xdebug模块
cat > /usr/local/php/etc/php.d/ext-xdebug.ini << EOF
[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
EOF
创建xdebug目录
mkdir /tmp/xdebug
chown www.www /tmp/xdebug
webgrind安装
webgrind是php代码,依赖PHP环境, 将webgrind代码拷贝到你的apache或者nginx的web路径下,可以正常访问.
cd /data/wwwroot/www.example.com
git clone https://github.com/jokkedk/webgrind.git
chown -R www.www /data/wwwroot/www.example.com
vim /data/wwwroot/www.example.com/webgrind/config.php
static $storageDir = '/tmp/webgrind';
static $profilerDir = '/tmp/xdebug';
创建webgrind目录
mkdir /tmp/webgrind
chown www.www /tmp/webgrind
分析
然后运行你的php项目,这时xdebug会在/tmp/xdebug/下生成一个 cachegrind.out.* 的文件。在页面打开webgrind首页。
http://www.example.com/webgrind/index.php
PHP执行慢分析工具xdebug + webgrind
Invocation Count:函数调用次数
Total Self Cost:函数本身花费的时间
Total Inclusive Cost:包含内部函数花费的时间
回复
举报
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖后跳转到最后一页
浏览过的版块
美国VPS综合讨论
干货茶馆
欧洲服务器
Archiver
|
手机版
|
小黑屋
|
MJJ论坛
Copyright
MJJ论坛
© 2022 All Rights Reserved.
快速回复
返回顶部
返回列表