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.
idekeylisted in a known features -- xdebug.org/docs/dbgp#feature-names 2) It should not cause issues with the actual ability to debug 3)idekeyis set in client settings (VSCode in this case) + Xdebug config param (in the actual .ini file or via-dparam 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)."hostname": "localhost",may cause issues (VSCode may not listen "properly") -- better delete it and try without it. 3) Most importantly, I do not see anybreakpoint_setlines -- looks like VSCode have not set any (unless you have removed those lines of the log).starting). The nextfeature_setthen 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 thatidekeycommand, as indeed it does not exist. I'll ping the maintainer.