VSCode 无法调试在 docker 容器中运行的 PHP 服务器 - 错误代码 #3 缺少选项

问题描述 投票:0回答:1

我知道 StackOverflow 上有几个关于这个问题的问题。相信我,我已经经历过其中的一些(这里这里这里以及其他一些)。

这些都没有帮助解决问题。

问题症状

程序不会在断点处停止。

我的环境

  • 操作系统:Ubuntu 22.04
  • IDE:VS代码1.85.1
  • PHP Web 应用程序:在具有 PHP 8.0-apache 的容器中运行
  • 插件:mysqli、xdebug

测试代码(第 2 行有一个断点):

<?php
echo xdebug_info();
#phpinfo()

launch.json

"version": "0.2.0",
"configurations": [
  {
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "hostname": "localhost",
    "log": true,
    "externalConsole": false,
    "pathMappings": {
      "/var/www/html": "${workspaceFolder}"
    },
    "xdebugSettings": {
      "idekey": "VSCODE"
    }
  },

xdebug.ini

[xdebug]
#zend-extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9003
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.client_host=host.docker.internal
xdebug.log=/tmp/xdebug.log
xdebug.idekey=VSCODE
xdebug.remote_autostart=1
xdebug.discover_client_host=0
xdebug.start_with_request=yes 
xdebug.mode=debug
xdebug.remote_connect_back=1

故障排除

检查了生成的

xdebug.log
的输出,这显示了一个奇怪的问题。

[18] Log opened at 2024-01-07 07:43:39.114700
[18] [Config] INFO: Control socket set up succesfully: '@xdebug-ctrl.18'
[18] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[18] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
[18] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/chk_mysqli.php" language="PHP" xdebug:language_version="8.0.30" protocol_version="1.0" appid="18" idekey="VSCODE"><engine version="3.3.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[18] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

[18] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

[18] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

[18] [Step Debug] <- feature_set -i 4 -n breakpoint_include_return_value -v 1
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="breakpoint_include_return_value" success="1"></response>

[18] [Step Debug] <- feature_set -i 5 -n idekey -v VSCODE
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" status="starting" reason="ok"><error code="3"><message><![CDATA[invalid or missing options]]></message></error></response>

[18] [Step Debug] <- feature_set -i 6 -n max_children -v 100
[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="max_children" success="1"></response>

[18] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" status="stopping" reason="ok"></response>

[18] Log closed at 2024-01-07 07:43:39.186601

输出显示所有成功,但上面

feature_set -i 5
处显示一处失败。

[[选项无效或缺失]]>

这是我第一次使用 PHP,所以感谢您帮助我解决这个问题。

php docker debugging xdebug
1个回答
1
投票

错误来自于

idekey
下有一个
xdebugSettings
条目。这些作为功能发送到 Xdebug,请参阅docs

如果需要设置,可以在

proxy
中的
launch.json
内进行设置。 VScode 调试适配器不支持 IDE KEY 过滤 - 无代理。

但是,如果您不使用 dbgpProxy,则无论如何都不需要 IDE KEY。正如 LazyOne 所说,清理你的 Xdebug 配置。

hostname
可能会导致 docker 连接问题。

这是我的建议:

"version": "0.2.0",
"configurations": [
  {
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "log": true,
    "pathMappings": {
      "/var/www/html": "${workspaceFolder}"
    }
  },
[xdebug]
#zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes 
xdebug.mode=debug
xdebug.log=/tmp/xdebug.log
© www.soinside.com 2019 - 2024. All rights reserved.