php-xdebug配置使用

摘要:
简要描述并简要记录php-xdebug的配置。它主要通过浏览器插件结合phpstrom分步实现断点调试,并通过xdebug生成性能分析报告。

 简要说明

简单的记录一下php-xdebug的配置,主要实现通过浏览器的插件配合phpstorm来进行断点调试,单步,以及通过xdebug来生成性能分析报告。
1.php-xdebug扩展的安装相对来说很简单,主要是通过apt-get、yum、pecl,或者直接通过编译的方式来进行安装都可以,很容易。
2.浏览器插件的安装,这次主要是使用chrome的xdebug-helper插件
3.phpstorm的配置

php.ini文件的修改

[xdebug]
;断点调试
xdebug.remote_enable=On ;远程调试
xdebug.remote_autostart=On ;开启远程调试自动启动
xdebug.remote_host=192.168.33.1
xdebug.remote_port=9001
xdebug.auto_trace=on ;启用代码自动跟踪
xdebug.collect_vars=On ;收集变量
xdebug.collect_return=On ;收集返回值
xdebug.collect_params=On ;收集参数
xdebug.idekey=hanpy
xdebug.remote_log="/tmp/xdebug.log"

;性能分析
xdebug.profiler_enable=On ;启用性能检测分析
;xdebug.trace_output_dir="/tmp/xdebug_profiler" ;指定堆栈跟踪文件的存放目录
xdebug.profiler_output_dir="/tmp/xdebug_profiler" ;指定性能分析文件的存放目录
xdebug.profiler_output_name="cachegrind.out.%p"
xdebug.profiler_enable_trigger=1

------------------------------------------------------------------------------------------

补充发现

xdebug.remote_autostart : 当此设置设置为1时,即使GET / POST / COOKIE变量不存在,Xdebug也将始终尝试启动远程调试会话并尝试连接到客户端。 (这个意思也就是不用安装浏览器插件了吧~~~)

xdebug官网有一个原理图,放上来记录一下

1️⃣ The IP of the server is 10.0.1.2 with HTTP on port 80
2️⃣ The IDE is on IP 10.0.1.42, so xdebug.remote_host is set to 10.0.1.42
3️⃣ The IDE listens on port 9000, so xdebug.remote_port is set to 9000
4️⃣ The HTTP request is started on the machine running the IDE
5️⃣ Xdebug connects to 10.0.1.42:9000
6️⃣ Debugging runs, HTTP Response provided

php-xdebug配置使用第1张

1️⃣ The IP of the server is 10.0.1.2 with HTTP on port 80
2️⃣ The IDE is on an unknown IP, so xdebug.remote_connect_back is set to 1
3️⃣ The IDE listens on port 9000, so xdebug.remote_port is set to 9000
4️⃣ The HTTP request is made, Xdebug detects the IP addres from the HTTP headers
5️⃣ Xdebug connects to the detected IP (10.0.1.42) on port 9000
6️⃣ Debugging runs, HTTP Response provided

php-xdebug配置使用第2张

phpstorm的配置

1.首先配置phpstorm的Debug,只有一个地方需要配置就是 Debug port 端口(和php.ini中的端口一样)。在Pre-configuration中已经清晰的写明白了步骤
1️⃣ 安装Xdebug
2️⃣ 验证配置
3️⃣ 安装浏览器插件
4️⃣ 开启phpstorm的Debug监听

php-xdebug配置使用第3张

2.配置phpstorm的Debug Servers
1️⃣ 配置host,项目的host
2️⃣ 配置文件目录的映射,就是本地文件和服务器文件的映射

php-xdebug配置使用第4张 

3.开启监听就可以了

php-xdebug配置使用第5张

4.最后就是要配置浏览器插件了。在前面的php.ini中有一个配置xdebug.idekey,需要把这个key配置到浏览器插件中,然后就可以开始单步调试了。
在浏览器中访问a.com,然后在项目中打断点,phpstorm就可以监听到。

性能报告文件的生成

xdebg官网:

https://xdebug.org

生成性能报告需要
https://github.com/jokkedk/webgrind/
https://github.com/jrfonseca/gprof2dot

gprof2dot安装
yum install python3 graphviz

yum 源没有3,特么的……,手动来吧……
wget http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz
tar -xzvf Python-3.3.0.tgz
cd Python-3.3.0
./configure --prefix=/usr/local/python3
make
make install

安装好之后给webgrind配置一个虚拟主机,直接访问就可以了,这个就比较简单了,忘记了可以看一下github里面的文档。
安装好之后要修改一下webgrind的配置文件,把python的路径修改一下,这样才能生成性能报告的那个图。

性能报告文件是这样的

php-xdebug配置使用第6张

免责声明:文章转载自《php-xdebug配置使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Oracle Sql 胡乱记mssql sqlserver 取消数值四舍五入的方法分享下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WSL2+PhpStorm+xdebug环境下端口连接不通

问题描述: 在WSL环境下搭建nginx+php-fpm环境,安装xdebug扩展后,按照常规的xdebug配置方法进行配置无法进入debug,查看xdebug日志,显示如下错误 [246] Log opened at 2020-08-05 11:09:01[246] I: Connecting to configured address/port:...

安装php xdebug调试工具及性能分析工具webgrind for windows

安装php xdebug调试工具及性能分析工具webgrind for windows 第一步:查看php版本等信息 phpinfo(); 上面是 x86 NTS VC14 第二步: 下载xdebug 官网https://xdebug.org/ 第三步: 下载扩展, 放入php的/ext 扩展目录 第四步: php.ini 开启扩展 配置其...

IDEA+PHP+XDebug调试配置

XDebug调试配置 临时需要调试服务器上的PHP web程序,因此安装xdebug,下面简单记录 安装xdebug 下载最新并解压 wget https://xdebug.org/files/xdebug-2.5.4.tgz tar zxvf xdebug-2.5.4.tgz cd xdebug-2.5.4/ 编译 按照README里的步骤安装 ./...

phpstorm 使用 Xdebug 调试代码

用过Java、C#等静态语言的同学调试代码经常是打个断点,然后轻松调试,而PHPer调试代码时经常是 echo $a;exit; 非常的不方便,有的同学有时候打完断点没删就给commit上去了,这就造成了很多困扰,有没有办法更优雅的调试呢?那当然有的,这里用到一个PHP模块xdebug,xdebug安装教程,使用它进行PHP代码调试,能有效减少工作量和B...

netbeans工具使用xdebug断点调试php源码

对有有经验的程序员,使用echo、print_r()、print_f()、var_dump()等函数足以调试php代码,如果需要在IDE工具中使用断点调试,xdebug就是一个非常好的php调试工具。对于不熟悉的代码,可以用Xdebug一步一步的查看请求过程和代码执行过程。 准备工作本地部署的server环境,推荐用phpStudy(内置xdebug),开...

使用visual studio code调试php代码

这回使用visual studio code折腾php代码的调试,又是一顿折腾,无论如何都进不了断点。好在就要放弃使用visual studio code工具的时候,折腾好了,汗~ 这里把步骤记录下来: 1、安装一站式php工具wampserver 我安装的是最新的3.1.3 64bit的版本,这个版本内置了4个版本的php,默认使用的是php 5.6.3...