在前进的路上 2019-06-27
print_r 、 log 、 var_dump 这类一次调试一行的方式PhpStorm 中配置过前端 页面 按菜单或按钮 调用 API 时,断点调试后端代码Postman 访问 API 时,断点调试后端代码如何愉快的在PhpStorm中进行Xdebug断点调试:https://blog.csdn.net/RobotYa...
如何愉快的在PhpStorm中进行Xdebug断点调试:https://segmentfault.com/a/11...
PHP xdebug 模块下载:https://xdebug.org/download.php
PHP xdebug 模块检测和下载:https://xdebug.org/wizard.php
Xdebug helper 浏览器插件:https://www.crx4chrome.com/cr...
PhpStorm 本地断点调试:https://blog.csdn.net/qq_2138...
Wamp3.1.0_x64,已经默认安装了 php_xdebugphp_xdebug 启用即可
PhpStorm 提示 xdebug版本与php版本不符,则需要自行下载 xdebug
php -r 'phpinfo();',复制终端输出的所有 phpinfo 信息访问地址:https://xdebug.org/wizard.php ,粘贴 phpinfo 信息到输入框,点击按钮进行分析当前 phpinfo 适配的 xdebug 版本,然后进行下载
phpinfo,并下载对应 xdebug 版本 
查看 php.ini 的 xdebug 配置,确保 xdebug.remote_enable = On 启用
; XDEBUG Extension [xdebug] zend_extension ="C:/Users/robot/Program/Wamp/Wamp3.1.0_64/bin/php/php5.6.31/zend_ext/php_xdebug-2.5.5-5.6-vc11-x86_64.dll" xdebug.remote_enable = On xdebug.profiler_enable = off xdebug.profiler_enable_trigger = off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir ="C:/Users/robot/Program/Wamp/Wamp3.1.0_64/tmp" xdebug.show_local_vars=0
参考文档
下载 xdebug.tgz 安装包
参考文档
安装 xdebug 模块
sudo apt-get install php-xdebug查看所有模块
php -m查找 xdebug 安装后的扩展路径
find /usr/ -name 'xdebug.so'/usr/lib/php/20151012/xdebug.so查找 php.ini 所在路径
php -i|grep 'php.ini' 或 php -r 'phpinfo();'/etc/php/7.0/cli/php.ini 或 /etc/php/7.0/apache2/php.ini[xdebug] zend_extension="/usr/lib/php/20151012/xdebug.so" xdebug.remote_enable=1 //xdebug.remote_handler=dbgp //xdebug.remote_mode=req //xdebug.remote_host=127.0.0.1 //xdebug.remote_port=9000
搜索关键词 debug,选择 Languages & Frameworks 下的 PHP -> Debug
端口 9000
多种调试配置方式:本质都是在 cookie 中自动添加 XDEBUG_SESSION=PHPSTORM
浏览器 Xdebug Helper 插件设置 idekey,用 debug 启动访问时,然后 cookie 会自动添加 XDEBUG_SESSION使用 请求体 request 中设置 XDEBUG_SESSION_START=PHPSTORM 请求参数,然后 cookie 会自动添加 XDEBUG_SESSION
URL 后追加,如 http://localhost:500/api/TestQ/xdebug?XDEBUG_SESSION_START=PHPSTORMbody 中追加,如 request.body.XDEBUG_SESSION_START=PHPSTORMPhpStorm 配置 Debug Configuration 与 Servers ,用 PhpStorm debug 启动访问时,URL会自动追加 XDEBUG_SESSION_START 请求参数,然后 cookie 会自动添加 XDEBUG_SESSION优点:
只要配置一致的 idekey=PHPSTORM 或在 cookie 中添加 XDEBUG_SESSION=PHPSTORM
Xdebug Helper 配置 idekey=PHPSTORM 后,在启用 debug 模式时,会自动在当前访问 url 所在域名(如 localhost:500)下的 cookie 中添加 XDEBUG_SESSION=PHPSTORM前端 只需要任意页面启用 Xdebug Helper 的 debug 模式即可,原理如上(但要确认你的 client request 携带的 cookie 可以正确到达 server requestPostman 只需要指定域名(如 localhost)的 cookie 中添加一次 XDEBUG_SESSION=PHPSTORM 即可PhpStorm 中只需开启 Listening Debug Connections(就是顶部路径栏中右边那个小电话图标)缺点:
Xdebug Helper 插件的 crx 文件,在浏览器扩展程序中拖放安装即可idekey 如下
PhpStorm
小电话
debug 模式 )
- 然后访问你的调试文件 或者 API 地址
Postman URL
cookie 中添加一次 XDEBUG_SESSION=PHPSTORM 
前端 node.js / express.js 等
XDEBUG_SESSION=PHPSTORM,如 response.cookie('XDEBUG_SESSION', 'PHPSTORM');node.js + express.js 直接在 app.js 中全局注入了 XDEBUG_SESSION 的 cookie - 虽然浏览器控制台的 Application 也显示 XDEBUG_SESSION 的 cookie 被正确写入  - 然后后台 API 却没有收到该 cookie,所以 PhpStorm 的 debug 也没有生效,**原因待查……**
优点:
缺点:
XDEBUG_SESSION_START=PHPSTORM 请求参数PhpStorm
浏览器 URL / 前端 URL
Disable 模式;或者直接卸载?XDEBUG_SESSION_START=PHPSTORM
Postman URL
?XDEBUG_SESSION_START=PHPSTORM
前端 node.js / express.js 等
XDEBUG_SESSION=PHPSTORM,如 request.body.XDEBUG_SESSION_START='PHPSTORM'Debug Configuration 与 Servers 方式优点:
XDEBUG_SESSION_START=PHPSTORM 请求参数缺点:
PhpStorm 中配置 Debug Configuration 与 Servers甲壳虫 图标,获取调试用的 XDEBUG_SESSION_START=session_keyPhpStorm 中配置 Debug Configuration 与 ServersEdit Configurations+ 号,新增一个 PHP Web Page... ,先新建一个 Web 服务
甲壳虫 图标,获取调试用的 XDEBUG_SESSION_START=session_key
XDEBUG_SESSION_START=12850,之后就是和《请求体 request 中通过 XDEBUG_SESSION_START 请求参数 方式》介绍的操作一样啦,这里不再赘述。
PHP安装xdebug模块,在 正确的 php.ini 下设置 xdebug.remote_enable=1或者 OnPostman在 API 域名下的cookie中添加XDEBUG_SESSION=PHPSTORMPhpStorm启动小电话,开启侦听