Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every php executable produces multiple Xdebug warnings #902

Open
artm opened this issue Dec 26, 2023 · 4 comments
Open

Every php executable produces multiple Xdebug warnings #902

artm opened this issue Dec 26, 2023 · 4 comments

Comments

@artm
Copy link

artm commented Dec 26, 2023

When using PHP CLIs inside the dev container they produce multiple warnings like:

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

The CLIs work as intended, but the warnings make the CLI experience uncomfortable, especially when repeated 20 times after the normal output of a utility.

As I understand the image enables Xdebug functionality so user's own PHP code can be debugged with F5. I know I won't be doing that, what is the best way to disable it in a dev container?

I tried to add

  "remoteEnv": {
    "XDEBUG_CONFIG": "mode=off"
  },

to devcontainer.json but it has no effect.

@artm
Copy link
Author

artm commented Dec 26, 2023

My current workaround is:

  "onCreateCommand": "sudo rm /usr/local/etc/php/conf.d/xdebug.ini",

@eljog
Copy link
Member

eljog commented Jan 4, 2024

I am not familiar with the PHP dev stack. Have you explored if the behavior can be controlled through the extension settings for PHP Debug extension that comes with the image? extension info here

@artm
Copy link
Author

artm commented Jan 4, 2024

I'm not familiar either, I'm running it in a dev container as I'm learning PHP :-)

As far as I understand the problem is that when xdebug is enabled (which it is in the image with the /usr/local/etc/php/conf.d/xdebug.ini config file) anything executed with php tries to connect to the debugger UI. When I'm using PHP-based CLIs in command line there is no debugger listening on port 9000, and it isn't my intention to debug these tools. I was hoping I would be able to disable the xdebug with environment variable XDEBUG_CONFIG as described here but it doesn't seem to help. Perhaps I'm doing something wrong.

I'll have a look at the VSCode extension documentation for some hints, but with only a small hope: the warning is printed exactly because I'm not using the extension when calling PHP.

@jeremyVignelles
Copy link

The warning are there because no debugger is listening. If you start debugging with vscode, the warnings will go away.
This is my .vscode/launch.json file for reference:

{
    // 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
        }
    ]
}

Then you can run the "Listen for XDebug" task and always keep it enabled to disable the warnings, but I'm not satisfied with that solution.

I wanted to turn off XDEBUG by default for CLI commands, but keep it enabled for web pages, so I put this hack in my devcontainer's dockerfile :

RUN echo 'export XDEBUG_MODE=off' >> /home/vscode/.bashrc

This means that every time I'm starting a terminal in vs code, XDebug is disabled by default for that session. I can enable it whenever I want by changing the debug mode for a single command:

XDEBUG_MODE=debug bin/phpunit

That's the best I came up with for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants