2

Let's say I have two microservices running in two different Docker containers: ServiceA and ServiceB. ServiceA makes an HTTP request to ServiceB and this one sends a response back. I would like to be able if it is possible, to start my debugging session in ServiceA (instance of PhpStorm) and switch it to ServiceB (instance of PhpStorm) once the call is sent and then get back to ServiceA. To be clear, I will have two PhpStorm windows opened: one for ServiceA and one for ServiceB.

Here are some notes from my current configuration:

  • ServiceA: PHP 7.4.x, Xdebug 3.0.4
  • ServiceB: PHP 7.2.x, Xdebug 3.0.4

The Xdebug settings are the same for ServiceA and ServiceB:

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.discover_client_host=true

As per the File | Settings | PHP | Debug configuration in PhpStorm they look as follow and are the same for ServiceA and ServiceB:

enter image description here

Since ServiceB should be Listening for Incoming connection this is how that little green bug toolbar looks like:

enter image description here

What issues I am having?

  • I am able to start the debugging session in ServiceA but it never switches to ServiceB, the session finishes correctly though.
  • The following "warning" spam my stdout logs for ServiceB:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: 172.18.0.9:9003 (from REMOTE_ADDR HTTP header), localhost:9003 (fallback through xdebug.client_host/xdebug.client_port)

What I could be possibly missing here?

Note: if more information is needed just ask me and I will add it

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • 1
    "xdebug.discover_client_host=true" that's very likely not going to do what you want. It uses HTTP headers to find out the IP address of where the HTTP request came from, and make Xdebug (try to) connect to an IDE on that machine. I bet `172.18.0.9:9003` does not have your IDE listening on it. – Derick Jun 09 '21 at 13:06

1 Answers1

0

The option xdebug.start_with_request = yes tells Xdebug to try to debug every single request/script. If Xdebug fails to connect to the debug client (it takes values from xdebug.client_host and xdebug.client_port) then it notifies you about that.

Normally such a messages will be written to the standard PHP's error log. Looks like you don't have it configured at all in your php.ini (as this is how it comes by default), therefore PHP sends it to your standard output instead.

If you want to prevent it from appearing on you terminal output you have to point the PHP error_log to a valid location.

Example of how I solved it in my case:

1- Edit your ini file:

sudo vi /etc/php/7.4/cli/php.ini

2- And add this line:

error_log = /var/www/log/php_error.log

NOTE: Change the previous routes to any valid directory you want.

3- Try again and the warning should disappear and now goes to the log file.