1

I know there are several questions on StackOverflow regarding this issue. Trust me I had gone through some of them (here, here and here and a few others).

None of these helped solving the issue.

Symptom of the problem

The program won't stop on the breakpoint.

My environment

  • OS: Ubuntu 22.04
  • IDE: VS Code 1.85.1
  • PHP web app: running in a container having PHP 8.0-apache
  • addons: mysqli, xdebug

Test code (has a breakpoint on line#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

Troubleshooting

Inspected the output of xdebug.log generated, and this shows a strange problem.

[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

The output shows all success but one failure at feature_set -i 5 above.

[[invalid or missing options]]>

This is my first time with PHP, so thanks for helping me out on this please.

3
  • 1
    1) I do not see idekey listed in a known features -- xdebug.org/docs/dbgp#feature-names 2) It should not cause issues with the actual ability to debug 3) idekey is set in client settings (VSCode in this case) + Xdebug config param (in the actual .ini file or via -d param when calling PHP executable) but not during runtime like this AFAIK. 4) Do not know about VSCode, but PhpStorm does not care about IDEKEY at all (it just ignores it) unless specifically told to use a specific key (e.g. with DBGProxy or in some multi-website scenario perhaps). Commented Jan 7, 2024 at 15:53
  • 1
    Side notes: 1) You are using Xdebug v3.3 but you still have v2 config params (that do nothing in v3) -- you may want to review them and delete old ones if v2 is no longer used. 2) Not a big expert in debugging PHP with VSCode, but "hostname": "localhost", may cause issues (VSCode may not listen "properly") -- better delete it and try without it. 3) Most importantly, I do not see any breakpoint_set lines -- looks like VSCode have not set any (unless you have removed those lines of the log). Commented Jan 7, 2024 at 15:57
  • I think there might be a bug here in Xdebug, where if you try to set a feature that doesn't exist, it also acts as as "run" (you see the status changing to starting). The next feature_set then also continues (incorrectly), running the script so it ends and VS Code never has the change to set breakpoints. However, I don't understand why VS Code sends that idekey command, as indeed it does not exist. I'll ping the maintainer. Commented Jan 8, 2024 at 11:24

1 Answer 1

4

The error comes from the fact that there is a idekey entry under xdebugSettings. These are sent to Xdebug as features, see docs.

If you need to set it, you can do that inside proxy in the launch.json. VScode debug adapter does not support IDE KEY filtering - without proxy.

However if you do not use dbgpProxy, you don't need the IDE KEY anyway. As LazyOne said, clean up your Xdebug config. hostname is probably causing docker connectivity issues.

Here is my suggestion:

"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
Sign up to request clarification or add additional context in comments.

1 Comment

FWIW, you don't need [xdebug] in INI files. PHP just ignores these header sections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.