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.
The program won't stop on the breakpoint.
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
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.
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