26

What is the workaround of this message for xdebug ang php?

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

This message showup when I run composer update on WSL2 installed with UBUNTU 20.01.

My current php version is php8 and xdebug3

Update:

This is the x-debug section

xdebug

__   __   _      _
\ \ / /  | |    | |
 \ V / __| | ___| |__  _   _  __ _
  > < / _` |/ _ \ '_ \| | | |/ _` |
 / . \ (_| |  __/ |_) | |_| | (_| |
/_/ \_\__,_|\___|_.__/ \__,_|\__, |
                              __/ |
                             |___/

Version => 3.0.1
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support

Feature => Enabled/Disabled
Development Aids => ✘ disabled
Coverage => ✘ disabled
GC Stats => ✘ disabled
Profiler => ✘ disabled
Step Debugger => ✔ enabled
Tracing => ✘ disabled

Debugger => enabled
IDE Key =>

Directive => Local Value => Master Value
xdebug.auto_trace => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.auto_trace" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.auto_trace"
xdebug.cli_color => 0 => 0
xdebug.client_discovery_header => no value => no value
xdebug.client_host => localhost => localhost
xdebug.client_port => 9003 => 9003
xdebug.cloud_id => no value => no value
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.collect_includes" => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.collect_includes"
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.collect_vars" => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.collect_vars"
xdebug.connect_timeout_ms => 200 => 200
xdebug.coverage_enable => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.coverage_enable" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.coverage_enable"
xdebug.default_enable => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.default_enable" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.default_enable"
xdebug.discover_client_host => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.gc_stats_enable" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.gc_stats_enable"
xdebug.gc_stats_output_dir => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.gc_stats_output_dir" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.gc_stats_output_dir"
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => no value => no value
xdebug.log => no value => no value
xdebug.log_level => 7 => 7
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.mode => debug => debug
xdebug.output_dir => /mnt/c/www/traces => /mnt/c/www/traces
xdebug.overload_var_dump => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.overload_var_dump" => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.overload_var_dump"
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable"
xdebug.profiler_enable_trigger => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable_trigger" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable_trigger"
xdebug.profiler_enable_trigger_value => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable_trigger_value" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_enable_trigger_value"
xdebug.profiler_output_dir => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_output_dir" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.profiler_output_dir"
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_autostart" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_autostart"
xdebug.remote_connect_back => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_connect_back" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_connect_back"
xdebug.remote_enable => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_enable" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_enable"
xdebug.remote_host => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_host" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_host"
xdebug.remote_log => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_log" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_log"
xdebug.remote_log_level => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_log_level" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_log_level"
xdebug.remote_mode => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_mode" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_mode"
xdebug.remote_port => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_port" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_port"
xdebug.remote_timeout => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_timeout" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.remote_timeout"
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.show_mem_delta" => This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-"xdebug.show_mem_delta"
xdebug.start_upon_error => default => default
xdebug.start_with_request => 1 => 1
xdebug.trace_enable_trigger => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_enable_trigger" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_enable_trigger"
xdebug.trace_enable_trigger_value => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_enable_trigger_value" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_enable_trigger_value"
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_output_dir" => This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-"xdebug.trace_output_dir"
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.trigger_value => no value => no value
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
Fil
  • 8,225
  • 14
  • 59
  • 85
  • 1
    Could be your Xdebug or PHP settings. I mean -- the reason why it's printed in the console (as it meant to be printed into the error log only). Please show `php -i` (which is the same as `phpinfo()`) -- mainly interested in Xdebug section and core PHP (error log related) for the moment. – LazyOne Dec 09 '20 at 12:59
  • 4
    As for "why it is there anyway" .. you must be having `xdebug.start_with_request = yes` (which is the same as `xdebug.remote_autostart = yes` for Xdebug v2) -- it tells Xdebug to try to debug **every single script** regardless of the "debug me" flag. Try disabling it and use debug on demand only (e.g. when starting from your IDE / cookie set by the Xdebug browser extension). – LazyOne Dec 09 '20 at 13:02
  • Yeah.. I just updated the question with x-debug info in it – Fil Dec 11 '20 at 02:27
  • 1
    Yeah it works. removing `xdebug.start_with_request = yes` fixed the issue. – Fil Dec 11 '20 at 02:30
  • Your Xdebug settings are standard values (those that I wanted to check). What your PHP's `error_log` value? It's possible that it gets redirected to the standard output somehow (that's my best guess based on the behaviour that you are seeing) as normally such messages are printed there (PHP's error log). Anyway, you can turn it off by setting `xdebug.log_level = 0`. Obviously, if you will need Xdebug log for info/debug purposes, make sure to comment out such line back (default value is `7`). – LazyOne Dec 11 '20 at 09:28
  • 1
    Please show what the value `error_log` PHP settings has (e.g. from `phpinfo();` output or just `ini_get('error_log');`). I bet it will be empty (or perhaps some incorrect location). – LazyOne Dec 11 '20 at 17:15
  • my php error_log has no value on phpinfo() – Fil Dec 12 '20 at 06:50

5 Answers5

55

What causes that message in the first place:

You have xdebug.start_with_request = yes (which is the same as xdebug.remote_autostart = yes for Xdebug v2). This option tells Xdebug to try to debug every single request/script regardless of the "debug me" flag.

If Xdebug fails to connect to the debug client (values from xdebug.client_host & xdebug.client_port .. or autodetected host if xdebug.discover_client_host is enabled) then it notifies you about that.

How to prevent it from appearing on my screen/in the output:

Xdebug uses standard PHP routines to write such warnings (e.g. standard PHP error_log() function). Normally such a message will be written to the standard PHP's error log. Looks like you do not have it configured at all in your php.ini (empty value) therefore PHP sends it to your standard output instead (so you still can have a chance to see it, as it might be important).

The solution is to point PHP's error_log ini setting to some valid location so you can read it when needed (path depends on your OS & distro, e.g. error_log = /var/log/php_error.log would be very common). If you do not need such log at all (have other logging system in place) -- use /dev/null or something similar instead.


You can also try xdebug.log_level = 0 but this should prevent Xdebug from logging anything, even if you specify xdebug.log.


Please also see this explanation from Xdebug author on "why it works this way": https://stackoverflow.com/a/65670743/783119

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Thanks for pointing this out, though it work with removing `xdebug.start_with_request = yes` this is also useful because from time to time sometimes I use `ini_set('display_errors', 1);` to display at the beginning of the script if something is not catch. – Fil Dec 12 '20 at 11:55
  • 2
    `xdebug.log_level=0` was the solution for me. – RyanNerd Dec 12 '20 at 14:35
  • Thank you. In my case these underlying Xdebug errors were in turn causing phpcs errors of the form `phpcs: Unknown error ocurred. Please verify that C:\Users\Nick\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=6 --warning-severity=6 C:\Bitnami\wampstack-7.4.12-0\apache2\htdocs\myfile.php - returns a valid json object.` I don't want a huge, forgotten log file building up, so setting `xdebug.log_level=0` is working for me, although, as a beginner, I am a little concerned about what important Xdebug errors I might miss. – Nick Hope May 24 '21 at 18:42
  • 2
    @NickHope Nothing important AFAIK. If debugging works OK for you already then nothing important will be missed. – LazyOne May 24 '21 at 19:59
  • @LazyOne I have an `error_log` path set in my php.ini but was still getting the same error to my console. I did have to set `xdebug.log_level=0` in order to fix it. But now will I not receive any output to my `error_log` path if something does go wrong? – CodeConnoisseur Jul 22 '21 at 20:32
  • @PA-GW See https://xdebug.org/docs/all_settings#log_level -- it tells what will be logged when value is '0'. – LazyOne Jul 22 '21 at 20:34
  • Useful info directly from Derick: https://stackoverflow.com/a/65670743/5882271 – kanlukasz Nov 16 '21 at 16:27
  • Contrary to what @RyanNerd reported, I just confirmed that setting `xdebug.log_level=0` via the INI or via an environment variable, will not suffice to suppress these (which implies this is considered a Critical error which is maybe debateable). The only thing that works is setting `error_log=/dev/null`, which obviously is extreme and impractical. I have opened https://bugs.xdebug.org/view.php?id=2092 to find out what the expected behavior is. – Rolf Kaiser May 11 '22 at 16:37
  • You assign these settings within `php.ini`, (located by running php --ini in the terminal) – Sam Oct 04 '22 at 22:50
4

I'm using: xdebug.start_with_request=trigger to trigger xdebug when I need it(with use of browser xdebug extension for web server debugging).

Or if I need to debug php script(using cli), I use phpstorm with configuration like this:

enter image description here

With this approach, I don't get this error and can use xdebug logs as always.

Volex
  • 633
  • 6
  • 16
3

Disable the xdebug browser extension when you aren't using it.

I use the VSCode debugger. When debugging was off in the IDE I was seeing the error in the log on every page visit because my chrome browser extension was still trying to invoke xdebug.

This happens despite having good php.ini settings for xdebug like:

xdebug.mode=debug

or

xdebug.start_with_request=trigger

Both documented here: Xdebug: Documentation

Mikhael Loo
  • 591
  • 5
  • 11
2

From the documentation of Xdebug about this kind of errors:

Occurs when Xdebug is trying to connect to a debuging client to start a debugging session.

The debugger could not make a connection to the client. The error message indicates which host and port combinations were tried, and through which configuration options it came to that conclusion.

An example:

Could not connect to debugging client. Tried: ::1:9003 (from REMOTE_ADDR HTTP header), localhost:9003 (fallback through xdebug.client_host/xdebug.client_port)

This message indicates that Xdebug first tried to use ::1:9003 (IPv6's localhost) from the REMOTE_ADDR header, and then it fell back to localhost:9003 as configured with xdebug.client_host and xdebug.client_port.

Suggested solutions:

  • Check whether your debugging client is listening on the indicated address and port. On Linux and OSX, you can use netstat -a -n | grep LISTEN to check.
  • Change xdebug.client_host and/or xdebug.client_port to the right address/hostname and port of where the debugging client is listening.
Ale
  • 944
  • 3
  • 14
  • 34
  • Oh this is usefull also, to determine where it is listening using `netstat -a -n | grep LISTEN` – Fil Dec 12 '20 at 12:39
0

I use Xampp and this is what I have in php.ini

[xdebug]
zend_extension=xdebug
xdebug.mode=develop,debug

When I want to debug some code, I use this FireFox add-on

Then I click on this button and activate debug mode:

enter image description here

This way I do not need to add xdebug.start_with_request = yes to the php.ini file and I will use xdebug just when I need it.


Update:

I just realized that if you enable this add-on but you forget to set a break point in your code you will see the error again which makes sense.

Ali Samie
  • 145
  • 2
  • 11