Home » Php » php – Visual Studio Code (VSCode) – Error: Debug Adapter Process Has Terminated Unexpectedly

php – Visual Studio Code (VSCode) – Error: Debug Adapter Process Has Terminated Unexpectedly

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:

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

Answer:

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.


>

Answer:

# 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 🙂

Answer:

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.