danielassayag
danielassayag

Reputation: 931

Variables are not showing up in VSCode / Xdebug PHP

I'm trying to configure xdebug with VSCode (VSCcode version 1.9.1).

php.ini

[Xdebug]
zend_extension = D:\php\ext\php_xdebug.dll
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_log = D:\site\xlog.txt

My default php port is 3000. ($_SERVER['SERVER_PORT'] = 3000 I can actually run phpinfo() at localhost:3000 and Xdebug port is set as xdebug.remote_port = 9000

Xdebug log:

Log opened at 2017-02-17 20:50:56
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///D:/site/index.php" language="PHP" xdebug:language_version="7.1.0-dev" protocol_version="1.0" appid="11384" idekey="Admin"><engine version="2.5.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>

<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

<- breakpoint_list -i 2
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>

<- breakpoint_set -i 3 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="113840001"></response>

<- run -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"></response>

<- stop -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="5" status="stopped" reason="ok"></response>

Log closed at 2017-02-17 20:50:56

launch.json:

{
"version": "0.2.0",
"configurations": 
[{

"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},

{

"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]

}

For the following test code :

$var = "test\n";
print $var;
var_dump($var);

I get this in the debug console :

test D:\site\index.php:5: string(5) "test "

But no variables in the debug list..

I don't know why but the variables don't appear in VSCode.

When I try to reach localhost:3000... here is what I get:

Log opened at 2017-02-17 21:38:16
I: Connecting to configured address/port: localhost:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-02-17 21:38:17

Upvotes: 2

Views: 8288

Answers (4)

Victor L
Victor L

Reputation: 73

Delete the watch variables firstly. This is a bug of VScode.

Upvotes: 0

PairrieNerd403
PairrieNerd403

Reputation: 61

I had a similar issue - same log entries you provided, same symptoms, nearly the same configuration. XDebug failed for me suddenly one day last week and all local variables began showing as 'undefined', no pop-over inspection, etc. Debugging the same code on another host I own which is nearly identical continued to work just fine.

After uninstalling and reinstalling XDebug and the VSCode extensions involved several times and attempting many config alterations, I eventually discovered the problem was being caused by an expression I'd placed in my watch list. Once the problematic expression was removed from my watchlist (which somehow survived all the uninstall / reinstall cycles) XDebug immediately started working properly again.

Sort of lame that a watchlist expression can cause the whole XDebug stack to curl up and die, but there it is. Thought this experience worth sharing as someone else will doubtless run into a similar problem in the future and wind up here looking for an answer.

Upvotes: 6

sc0rp10n.my7h
sc0rp10n.my7h

Reputation: 341

You need to change the host port to 3000

Follow this:

vscode > debug > gear icon > launch.json

{
"version": "0.2.0",
"configurations": [
{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000
},
{

"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 3000
}
]
}

This worked for me

Upvotes: -1

Martin Andersen
Martin Andersen

Reputation: 313

Got it working (only tested with php version 7).

  1. Start by downloading the correct xdebug version here: https://xdebug.org/wizard.php

follow the steps..

vscode > debug > gear icon > launch.json

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000
    },
    {

    "name": "Launch currently open script",
    "type": "php",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}",
    "port": 9000
    }
]
}

vscode > File >preferences > settings.json > WORKSPACE SETTINGS

    // Place your settings in this file to overwrite default and user settings.
{
      "php.validate.executablePath": "C:\\Program Files (x86)\\php\\php7\\php.exe",
      "php.validate.enable":true
}

php.ini add this to end of file (note there is no path slashes in "zend_extension")

[Xdebug]
zend_extension = php_xdebug-2.5.4-7.0-vc14-nts.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_log = C:\Temp\Xdebug_log.txt

also watch this youtube guide:

https://www.youtube.com/watch?v=xME6uHYTcLU

Finally, when configuration is done, here is how to get the debugger in vs code to show the variable, watch, callstack:

  1. start webserver (eg port 8080.. just not on port 9000)
  2. vscode > Click; Start debuggin ( listen for Xdebug)
  3. in Chrome > click RELOAD (this will trigger and start the debugging) Done.

Upvotes: 1

Related Questions