microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.41k forks source link

[PHP] Debugging Error Xdebug: [Step Debug] Could not connect to debugging client #11 #1052

Open stefnats opened 3 years ago

stefnats commented 3 years ago

Hello,

i'm using this container with the following config (devcontainer.json):

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.0/containers/php
{
    "name": "PHP",
    "build": {
        "dockerfile": "Dockerfile",
        "args": { 
            // Update VARIANT to pick a PHP version: 8, 8.0, 7, 7.4, 7.3
            "VARIANT": "8",
            "NODE_VERSION": "lts/*"
        }
    },

    // Set *default* container specific settings.json values on container create.
    "settings": { 
        "php.validate.executablePath": "/usr/local/bin/php"
    },

    // Add the IDs of extensions you want installed when the container is created.
    "extensions": [
        "felixfbecker.php-debug",
        "bmewburn.vscode-intelephense-client",
        "mrmlnc.vscode-apache",
        "calebporzio.better-phpunit"
    ],

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [8080],

    // Use 'portsAttributes' to set default properties for specific forwarded ports. More info: https://code.visualstudio.com/docs/remote/devcontainerjson-reference.
    "portsAttributes": {
        "8000": {
            "label": "Hello Remote World",
            "onAutoForward": "notify"
        }
    },

    // Use 'otherPortsAttributes' to configure any ports that aren't configured using 'portsAttributes'.
    // "otherPortsAttributes": {
    //      "onAutoForward": "silent"
    // },

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"

    // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode"
}

When i run any php process i receive this error

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9000 (through xdebug.client_host/xdebug.client_port) :-(

Dockerfile is still as is: https://github.com/microsoft/vscode-remote-try-php/blob/67e233b925a64f90a46092879ed82b9e6d89f19e/.devcontainer/Dockerfile

Am i doing something wrong? Thanks in advance!

Steps to Reproduce:

  1. Use the devcontainer from here: https://github.com/microsoft/vscode-remote-try-php/tree/main/.devcontainer
  2. Run a phpunit test or do any other php command
  3. See the error message Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9000 (through xdebug.client_host/xdebug.client_port) :-(

Edit: It happens too with this Version: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.0/containers/php/.devcontainer

stefnats commented 3 years ago

In terminal when i type in:

# lsof -i :9000 | grep LISTEN

I don't get a result.

Chuxel commented 3 years ago

Do you have a repository with this problem?

The steps in vscode-remote-try-php includes running php -S 0.0.0.0:8000 which appears to work.

mpriscella commented 2 years ago

I’m experiencing this as well. After some digging, it appears to be related to this line where xdebug.start_with_request is set to yes.

Based on this stackoverflow answer written by the author of xdebug, I think xdebug.start_with_request should be set to trigger. This would suppress the Could not connect warning and still allow users to start an xdebug session using a browser extension or by setting an environment variable.

If this sounds like a good solution, I would be more than happy to create a PR.

Chuxel commented 2 years ago

Unfortunatley it does not look like the VS Code extension works with the property set to "trigger". Certainly am open to it if it works there.

mgenereu commented 2 years ago

I call php -dxdebug.mode=off if I need it off but since this is the container for development, I just leave the XDebug running whenever I'm running PHP code.

lifetin commented 1 year ago

原 xdebug.client_port=9900 换成 xdebug.client_port=9003

就可以了

halmai commented 1 year ago

This is not a VSCode issue, it happens with PhpStorm as well. See my answer here: https://stackoverflow.com/a/76643876/3823826