Disable Xdebug 3 "Could not connect" message in CLI
Asked Answered
B

7

27

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?

Bruit answered 9/12, 2020 at 8:30 Comment(7)
Could be your Xdebug settings. It does not print such stuff here. What are yours? Please show Xdebug section of phpinfo() or just xdebug_info().Celtuce
P.S. Similar question (in case if some updates will be posted there): https://mcmap.net/q/488413/-xdebug-step-debug-could-not-connect-to-debugging-client-tried-localhost-9003-fallback-through-xdebug-client_host-xdebug-client_port/783119Celtuce
I do have xdebug.remote_autostart = yes - still, I would prefer that it does not show that message when it can't connect. Can't I disable that error message?Bruit
I believe it's either one of the Xdebug settings or PHP itself. If you can provide your phpinfo() / php -i output I may compare with mine... as I do not see such warnings here when I do the same (I'm on Windows ... but I doubt it will make any difference here). Right now I believe it could be one of the xdebug.XXX options .. or perhaps how error_log is handled (because that's where such message gets normally written).Celtuce
It's interesting how StackOverflow did not let me post my config, saying something like "Too much code, too little explanation." From your referenced answer I concluded you meant @xdebug.remote_autostart = yes@ - but funny how it probably built a ratio of code vs text and said too much code.Bruit
Just in case: xdebug.remote_autostart = yes is Xdebug v2 option while Xdebug v3 uses xdebug.start_with_request = yes instead xdebug.org/docs/upgrade_guide. I've checked all options I could think of .. and could not locate the one that would force such entry to be printed in the normal output (except some sort of PHP's error log redirection .. as that's where such message normally goes). No better ideas from me (except perhaps checking Xdebug's Bug tracker for possible tickets) and therefore xdebug.log_level = 0 sounds like a good solution here.Celtuce
Check https://mcmap.net/q/488413/-xdebug-step-debug-could-not-connect-to-debugging-client-tried-localhost-9003-fallback-through-xdebug-client_host-xdebug-client_port -- configure error_log setting properly.Celtuce
S
34

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.

Spates answered 9/12, 2020 at 14:19 Comment(10)
Xdebug should write such text into PHP error log ... and it does it here on Windows 10 (PHP 7.4 and 8.0 -- NTS build, x64). I do not see such warning here when doing my tests in terminal -- it arrives into the log ifle as it should (using default xdebug.log_level value, which is 7). Perhaps it's some output redirection (error output stream or alike).Celtuce
With echo "<?php" | php on Ubuntu with default xdebug.log_level and without listing to PHP debug connection, I get this message: "Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-("Spates
I understand that. It just I have no idea why it happens for you and does noting like that for me... Can you post your xdebug config (xdebug_info() output) -- you can redact IP/host name or other private parts (share it as a link). I'm interested to know why it happens.Celtuce
This worked for me. My rationale is when I debug and the xdebug does not connect, it is pretty obvious to me - it does not stop at a breakpoint. Working with Drupal 8 and Drush, I get spammed with the warnings that it could not connect even if I simply don't set a breakpoint.Bruit
@LazyOne: I only added xdebug.start_with_request=yes to control debugging only through PhpStorm without having the need for additional commands in CLI or browser extensions. Here is my xdebug_info() output: pastebin.com/VEqhQyQ1Spates
@haby What's the value of the error_log PHP settings. (e.g. from phpinfo(); output or just ini_get('error_log');). I believe it will be empty (or perhaps some incorrect location). If you set it to some proper location (e.g. something like /var/log/php_error.log or maybe even /dev/null - -depends n your OS and distro) then you should not see such error in the first place. Can you do that and check the same that you did in your first comment here?Celtuce
You're right, it's empty. Setting it to the suggested filename and setting correct permissios, the error message disappear. I hadn't such behaviour with xdebug2, but thanks anyway.Spates
@haby "I hadn't such behaviour with xdebug2" When Xdebug 3 sees that you are still using v2 params, it also notifies you about that using the same way. This is done on purpose to make user aware of "something might be wrong, you may want to look into it".Celtuce
@Celtuce ahhhh , enlightened ... thks. Fixed it for me.Rheims
Since v3.1 this answer is better option https://mcmap.net/q/499272/-disable-xdebug-3-quot-could-not-connect-quot-message-in-cliEmpathy
F
14

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.

Fragment answered 20/6, 2021 at 16:16 Comment(3)
Excellent! This got rid of the warnings and did not break the PHP Debug extension for VS Code.Merete
This fixed it for me -- the Xdebug warning was causing PHPUnit tests to fail on the CLI.Diathermy
Great answer: +50Genovese
E
7

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

Empathy answered 16/2, 2022 at 6:25 Comment(0)
C
1

If you are running a PHP script or command you can set INI entry using -d:

php -d xdebug.log_level=0 your_sript.php
Concubinage answered 28/6, 2023 at 17:41 Comment(0)
P
0

if you only need to suppress the output for one call you can use this - e.g. show version: XDEBUG_CONFIG="log_level=0" composer -v

Pact answered 3/3, 2023 at 11:39 Comment(0)
C
0

Changing the php.ini 'xdebug.start_with_request' form 'yes' to 'trigger' solved my issue , I use MAMP.

xdebug.start_with_request = trigger
Courtesy answered 16/6, 2023 at 14:49 Comment(0)
G
-4

This is what you need:

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
Gunner answered 22/3, 2021 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.