PHP+vscode开启调试debug

目录

配置PHP

  • 打开php.ini中添加xdebug扩展
ini 复制代码
[Xdebug]
zend_extension=D:/Code/skpanelN/V1.1/system/php/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=Off
xdebug.profiler_enable=Off
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

配置VSCODE

安装PHP调试扩展(注意作者)

打开设置,指定php.exe地址

  • php 和 php debug都要设置


  • php和php debug的setting.json在一个地方,可以一起设置了,注意需要反斜杠

配置调试参数

  • 端口和之前ini设置一致就行

进行调试

  • PHP中添加断点

  • 开启调试

  • 刷新网页,到断点vscode闪动,点击单步

问题

  • 开启xdebug后PHP速度明显降低,是因为每次连接都要监听9000端口
  • 解决方法:
  • 自动触发改成按需触发
ini 复制代码
xdebug.remote_enable=1
xdebug.remote_autostart=0 #按需要触发

浏览器控制台触发

  1. 在页面打开 DevTools Console,执行:
js 复制代码
document.cookie = "XDEBUG_SESSION=VSCODE; path=/";
  • 然后 $.ajax({...}) 的 POST 请求会自动带上 cookie,断点就会命中。
  1. 关闭触发:
js 复制代码
document.cookie = "XDEBUG_SESSION=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";

VSCODE 只是一个 session 名字,你用 PHPSTORM 也行,关键是 cookie 名必须是 XDEBUG_SESSION。

get

?XDEBUG_SESSION_START=1

post

js 复制代码
$.ajax({
  url: sysapi.sys_api_fixedQueryHis + '?XDEBUG_SESSION_START=PHPSTORM',
  type: 'post',
  ...
});
js 复制代码
$.ajax({
  url: sysapi.sys_api_fixedQueryHis,
  type: 'post',
  contentType: 'application/json',
  dataType: 'json',
  headers: {
    'XDEBUG_SESSION': 'PHPSTORM'
  },
  data: JSON.stringify(param),
  ...
});

cookie插件

Xdebug Helper (Chrome/Edge)

选择 IDE key(常用 PHPSTORM),点 "Debug"

之后你所有请求(包括 AJAX POST)都会带上 cookie,断点就会命中。

相关推荐
JaguarJack1 天前
告别 Laravel 缓慢的 Blade!Livewire Blaze 来了,为你的 Laravel 性能提速
后端·php·laravel
郑州光合科技余经理2 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1232 天前
matlab画图工具
开发语言·matlab
dustcell.2 天前
haproxy七层代理
java·开发语言·前端
norlan_jame2 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone2 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054962 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
QQ5110082852 天前
python+springboot+django/flask的校园资料分享系统
spring boot·python·django·flask·node.js·php
WeiXin_DZbishe2 天前
基于django在线音乐数据采集的设计与实现-计算机毕设 附源码 22647
javascript·spring boot·mysql·django·node.js·php·html5
遥遥江上月2 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js