Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code 中如何使用 xDebug? #130

Closed
isecret opened this issue Apr 9, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@isecret
Copy link

commented Apr 9, 2019

xDebug 拓展已经安装了,然而 VS Code 这边配置后似乎不起作用,断点没有效果。是需要把 PHP 容器里的 9000 端口映射出来吗?

@daulCN

This comment has been minimized.

Copy link

commented Apr 10, 2019

没用过vscode,不过应该和PhpStorm差不多,首先你需要判断是否有接收到服务端发来的请求,如果接受到了,只需要配置映射目录就行,不需要宿主机的php支持

@isecret

This comment has been minimized.

Copy link
Author

commented Apr 11, 2019

@daulCN 感谢。我打开了 log 日志输出如下:

// 开启时
<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }
// 终止时
-> disconnectRequest
{ command: 'disconnect',
  arguments: { restart: false },
  type: 'request',
  seq: 3 }
<- disconnectResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 3,
  command: 'disconnect',
  success: true }

看样子是已经收到了服务器的响应,我设置的断点仍无法正常工作,后续的映射目录该如何配置?在同时存在多个项目的情况下呢?

@isecret

This comment has been minimized.

Copy link
Author

commented Apr 11, 2019

我在服务器上新增了 xdebug.remote_log 配置,然而并没有找到日志。很奇怪。

@netwu

This comment has been minimized.

Copy link

commented Apr 15, 2019

9000端口已经被 php-fpm用了,所以得修改xdebug默认的端口,我用的9001,php.ini 配置信息

[XDebug]
xdebug.remote_enable = 1
#xdebug.remote_mode = "req"
#xdebug.remote_connect_back = on
xdebug.remote_autostart = on
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_port = 9001
#xdebug.remote_log = /var/log/php-fpm/x-debug-remote.log

vsCode 的 launch.json

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/html/项目目录": "${workspaceRoot}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001
}
]
}

@isecret

This comment has been minimized.

Copy link
Author

commented Apr 15, 2019

@netwu 十分感谢,你的配置让它正常工作了,我一直没想到过可能是端口的锅。

@isecret isecret closed this Apr 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.