0

For some reason Xdebug is not connecting to the port that I have specified for it.

.ini file contents:

xdebug.mode=debug
xdebug.log=/var/log/xdebug/xdebug.log
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.client_port=10000

PhpStorm settings:
PhpStorm settings

I used to have my PhpStorm set to listen on port 9003, but changed it in an attempt to resolve the issue.

sudo lsof -i :9003:

COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
phpstorm 8680 lodewykduminy   71u  IPv6 0x994c1e5e6b18981f      0t0  TCP *:9003 (LISTEN)

sudo lsof -i :10000 does not show anything listening on the port.

When navigating to a page that would cause a breakpoint to be hit, the following is logged:

[122] Log opened at 2022-01-19 00:46:24.792450
[122] [Step Debug] INFO: Checking remote connect back address.
[122] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[122] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[122] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.1:10000.
[122] [Step Debug] WARN: Creating socket for '172.18.0.1:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:10000. :-|
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', connect: Address not available.
[122] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.18.0.1:10000 (from REMOTE_ADDR HTTP header), localhost:10000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[122] [Step Debug] INFO: Checking remote connect back address.
[122] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[122] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[122] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.1:10000.
[122] [Step Debug] WARN: Creating socket for '172.18.0.1:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:10000. :-|
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', connect: Address not available.
[122] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.18.0.1:10000 (from REMOTE_ADDR HTTP header), localhost:10000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[122] [Step Debug] INFO: Checking remote connect back address.
[122] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[122] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[122] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.1:10000.
[122] [Step Debug] WARN: Creating socket for '172.18.0.1:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:10000. :-|
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', poll success, but error: Operation in progress (29).
[122] [Step Debug] WARN: Creating socket for 'localhost:10000', connect: Address not available.
[122] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.18.0.1:10000 (from REMOTE_ADDR HTTP header), localhost:10000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[122] Log closed at 2022-01-19 00:46:25.492820

Not sure what my next step should be.

(EDIT)

I've updated my docker setup to hold port 10000 in an attempt to resolve the issue:

Unfortunately the logs remain the same, with the following being show when I run sudo lsof -i :10000: enter image description here

Full xdebug_info():

enter image description here enter image description here enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Skytiger
  • 1,745
  • 4
  • 26
  • 53
  • Accordingly to your info (`sudo lsof -i :9003`) PhpStorm listens on **IPv6** while Xdebug tries to connect via **IPv4**... I may only suggest to check your MacOS network settings to ensure that IPv4 has a priority over IPv6. Also check if `-Djava.net.preferIPv4Stack=true` is present (so the IDE targets IPv4 instead of IPv6). e.g. see https://youtrack.jetbrains.com/issue/WI-30173#focus=Comments-27-1444510.0-0 and the whole ticket. – LazyOne Jan 19 '22 at 10:33
  • *"`sudo lsof -i :10000` does not show anything listening on the port."* Have you restarted PhpStorm debugger after that? If you were listening on 9003 port and then just changed the port number, this will not stop PhpStorm from listening there, you also need to stop and start listening for debug connections again. Or just exit and open PhpStorm again if stop/start the IDE debugger sounds confusing. – LazyOne Jan 19 '22 at 10:35
  • *"I've updated my docker setup to hold port 10000 in an attempt to resolve the issue:"* WTF? Why? You seem to know that it's Xdebug that connects to the IDE and NOT other way around. Now you have Docker listening on that port which makes PhpStorm unable to use it. So why did you do this? – LazyOne Jan 19 '22 at 10:37
  • P.S. If you are using Xdebug inside the docker then you should not use `localhost` for `client_host`. Use what Docker says: `host.docker.internal` – LazyOne Jan 19 '22 at 10:44
  • @LazyOne yep I've swapped over to using that, thank you! – Skytiger Jan 19 '22 at 19:22

1 Answers1

0

I found a work-around for this. See my answer here: https://stackoverflow.com/a/76643876/3823826

TLDR: use the 192.168.x.x address of the host instead of the 172.17.x.x

Csongor Halmai
  • 3,239
  • 29
  • 30