Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Xdebug 3 "Could not connect" message in CLI

When working with Xdebug 3 in CLI, it constantly reports the message when there are no breakpoints set:

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

Is there a way to disable that message form showing in CLI?

like image 708
Alexei Rayu Avatar asked Dec 09 '20 08:12

Alexei Rayu


People also ask

How do I disable xdebug in composer?

As of Xdebug 3, it is possible to disable the Xdebug completely by setting the option xdebug. mode to off , or by setting the environment variable XDEBUG_MODE=off . It is very easy to disable Xdebug just for composer, by aliasing composer . You can add the alias to your $HOME/.

How do I know if xdebug is working?

Given that, you can confirm that xDebug is installed and in place by trying the following: 1) phpinfo() -- this will show you all the extensions that are loaded, including xDebug. If it is there, then it's a safe bet that it's working. 2) If that isn't good enough for you, you can try using the var_dump() function.

How do I debug using xdebug?

You can find it in the extension window and install it. After installation, you must reload the VSCode window. Now, again run phpinfo(); method in any PHP file to check if Xdebug is enabled or not. Now click on the debug console tab and click on add configuration.


3 Answers

Unfortunately, the only way to disable this error is to disable generally ALL errors & warnings in xdebug.ini:

xdebug.log_level = 0

Hopefully there are other ways in future xdebug versions (imho this should only be a weak warning).

EDIT: As LazyOne mentioned, it's also possible to set an value for error_log in php.ini, for example /var/log/php_error.log. With that change, the log entries are written to this file and not sent to stderr.

like image 96
haby Avatar answered Nov 02 '22 23:11

haby


In my case the problem was that Xdebug tried to run on every request and since I didn't do debugging on every page refresh errors like Xdebug: [Step Debug] Could not connect to debugging client were reported and are understandable.

The most obvious solution with xdebug.log_level = 0 of course worked, but this was too broad and too blind way to fight this for me. So I checked the documentation, and the best way to get rid of that error in my opinion is to tell Xdebug when it should really run and when not, so the right option in my case is:

xdebug.start_with_request = trigger

as the documentation says:

The functionality only gets activated when a specific trigger is present when the request starts.

The name of the trigger is XDEBUG_TRIGGER, and Xdebug checks for its presence in either $_ENV (environment variable), $_GET or $_POST variable, or $_COOKIE (HTTP cookie name).

and I recommend checking at least that part of their docs because there's more info and you can even do more fine tuning if needed.

like image 20
Picard Avatar answered Nov 02 '22 23:11

Picard


Starting from version 3.1, xdebug does not redirect its logs to php logs if you set the path to the log file. In my case, I use the following settings and these messages no longer dazzle the eyes in the console

xdebug.log=/var/www/var/log/xdebug.log
xdebug.log_level=3

PR for this issue: https://github.com/xdebug/xdebug/pull/738

like image 23
Антон Михалёв Avatar answered Nov 02 '22 23:11

Антон Михалёв