8

I'm struggling with this error message. Sometimes I cannot run xdebug on Visual Studio Code after upgrading or restarting the editor. Here's a screenshot of the error:

enter image description here

Can anyone help me with this?

pillravi
  • 4,035
  • 5
  • 19
  • 33
Aditya Kresna Permana
  • 11,869
  • 8
  • 42
  • 48

3 Answers3

7

After several minutes to find out what happens on my machine, i figure it out how to solve my problem.

Because the xdebug is running based on port 9000 and i see on the Debug Console (VSCode) has message listen EADDRINUSE :::9000, i think there is an another process running on port 9000 so i check what process running on it by this command

sudo netstat -nlp | grep :9000

The command above will show you what process running on port 9000, then i get this result

tcp6       0      0 :::9000                 :::*                    LISTEN      14856/hhvm

HHVM was take over port of xdebug by default, so i need to take it service down or change the port number.

Tips:

You can also use lsof to view process on specific port

lsof -t -i :9000
Aditya Kresna Permana
  • 11,869
  • 8
  • 42
  • 48
  • Hi @JackZhai sure i will, but i need to wait like 23 hours for accepting my own answer, thanks man :) – Aditya Kresna Permana Oct 18 '16 at 05:18
  • got it, thanks for your warning, you can mark it as the answer now:) – Jack Zhai Oct 20 '16 at 06:09
  • @AdityaKresnaPermana Thx for the answer! To which port did you change xdebug? – Carol.Kar Dec 26 '17 at 19:13
  • @mrquad in that situation I'm didn't change the port for xdebug, instead change HHVM configuration so it is not conflicted with xdebug process. but if you wanna try to change that go to your php.ini and change the parameter `xdebug.remote_port` to your new port number, and change the xdebug configuration on VScode. – Aditya Kresna Permana Dec 29 '17 at 10:17
  • 2
    I had another VSCode debug session running so restarted VSCode and this error disappeared. – Clemens Tolboom Mar 15 '18 at 09:57
3

I had same issue while I was start using VSCode. Well i took 3 hours to figure out what is exactly issue, I just stared with some step by step debugging like what port being used and what are the other settings.

Finally I was lucky and got the solutions :) So I shared with everyone. You can check what is my findings and what you should need to setup to get Xdebug work with VSCode.

#VSCode & PHP Debug

Setup Xdebug in VS Code to debug your PHP Code on fly. follow the step by step instruction to setup xdebug properly.

Gif action:

enter image description here


How to setup PHP Debugging (xdebug) with VSCode?

1. First of all Install VSCode

2. Install PHP Debug Adapter for Visual Studio Code

3. Install XDebug in WAMP


  • Open phpinfo in browser
  • Copy the view sorce code
  • Paste in https://xdebug.org/wizard.php
  • Download the suggested xdebug dll file
  • Paste dll file inside the current version of php folder ext or zend_ext folder
  • Open phpinfo and find 'Loaded Configuration File' to know what php.ini file wamp using
  • Open php.ini file & place below code

[Xdebug] zend_extension="FULL-XDEBUG-DLL-FILE-PATH"

Example

;zend_extension="d:\wamp64\bin\php\php7.1.9\zend_ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"

OR

;zend_extension="d:\wamp64\bin\php\php7.1.9\ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"

xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.remote_host="localhost"

xdebug.profiler_output_dir="<tmp path>"
;Example
;xdebug.profiler_output_dir="d:\wamp64\tmp"

4. Restart WAMP Server

Open phpinfo & find xdebug, If found then you have installed xdebug successfully! If Wamp Restart But localhost not opening then try to change PORT. May PORT using by any other application already.


How can you find out which process is listening on a port on Windows?

Setup XDebug in VSCode


Example JSON - launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "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
        }
    ]
}

5. Update VSCode Setting for PHP to add PHP Executable Path

"php.validate.run": "onType",
"php.validate.executablePath": "<Your-Full-PHP-Path>php.exe"

6. Save and restart VSCode

Open PHP Project Folder and try to Debug code..If you are getting following error

VS Code Debug adapter process has terminated unexpectedly

or

VS Code Console Error -> listen EADDRINUSE::900)

Thats mean the PORT 9000 is currently using by another programe, You may have running PHPStorm Xdebug or any other application who using the PORT 9000. Try to Close the PHPStorm or Other programe and try to debug again.


Still getting error then try to find which program using PORT 9000 and kill them .. Still getting error try to change PORT in php.ini and launch.json and restart wamp and VSCode.

Now you can see XDEBUG working in VSCode.


> #### Example Code to test

<?php

/*
|--------------------------------------------------------------------------
| PHP XDebug Code Example - VS Code
|--------------------------------------------------------------------------
|
|  Information:
|
|   VS Code         :
|     Version       :   1.19.2
|     Commit        :   490ef761b76b3f3b3832eff7a588aac891e5fe80
|     Date          :   2018-01-10T15:55:03.538Z
|     Shell         :   1.7.9
|     Renderer      :   58.0.3029.110
|     Node          :   7.9.0
|     Architecture  :   x64
|
|   Windows         :   10
|
|   WAMP Server     :   3.1.0
|       PHP         :   7.1.9
|       APACHE      :   2.4.27
|       MySQL       :   5.7.19
|
|   PHP INI PATH    :   D:\wamp64\bin\apache\apache2.4.27\bin\php.ini
|       [Xdebug]
|       zend_extension              =   "d:\wamp64\bin\php\php7.1.9\zend_ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"
|       xdebug.remote_enable        =   1
|       xdebug.remote_autostart     =   1
|       xdebug.remote_port          =   "9000"
|       xdebug.profiler_enable      =   1
|       xdebug.remote_host          =   "localhost"
|       xdebug.profiler_output_dir  =   "d:\wamp64\tmp"
|
*/


// first loop
for ($i=0; $i < 10; $i++) {
        echo $i;
}

echo PHP_EOL;

// second loop
for ($i = 0; $i < 20; $i++)
{
    echo $i;
}

/* End of file php-test.php */
/* Location: /wamp64/www/test/php-test.php */

Thanks :)

Nono
  • 6,986
  • 4
  • 39
  • 39
  • 4
    You should include all the details in your answer here. Links to other sites can become broken and no longer work. Users of stackoverflow should not have to follow a link off site to find an answer. Someone with your reputation should already know this. – Matthew Goheen Apr 23 '18 at 15:39
  • I am not voting up your answer for the same reason Matthew Goheen mentioned. – Lucio Mollinedo Sep 11 '18 at 13:37
  • 1
    @MatthewGoheen Yes, you are right, The answer must be in SO only the 3rd party links are not reliable, they could be disappeared at anytime without any prior warning. Thanks to dragging me in right direction :) – Nono Sep 25 '18 at 22:36
  • @NeerajSingh Very Nice!. – Matthew Goheen Sep 26 '18 at 15:44
  • `xdebug.remote_autostart=on` This is missing from the default xdebug.ini in Arch linux package... thanks! – SparK Nov 06 '18 at 15:18
0

I hit this error on an old version of VS Code, I updated to v1.37.1 and that fixed it.

Updating VS Code I hit an Access Denied error, it prompted me with a Dialog Failed Delete Marker. I ran Process Monitor and clicked Retry in the Dialog and the update finished and worked.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321