Is PHP debugging supposed to work?

I tried to debug a PHP application. I also tried the Symfony demo.

The first problem is that the Apache that gets launched by default does not have debugging enabled.

Then, in the debugger I can launch another instance, I can set a breakpoint, and execution stops there. But then the process dies. This is not helpful at all.

On https://www.gitpod.io/docs/languages/php/ the demo shown in the animated gif has only simple variable-setting code that runs once and exists. The demo does not even use the HTML Preview.

However, as we all know, PHP is used for websites where a request comes in and some code produces a response. And that response is shown in the HTML Preview where the server continues running. That is what I want to debug. Not simple variable-setting code.

So, my question is, after seeing PHP debugging advertised on the Gitpod website, is PHP debugging working at all for real applications?

Then, show me an example where this works.

Hello, sorry PHP debugging isn’t working for you. Could you send a link to the repository where the issue is occurring?

Hello, so basically what we would like to do is to have a server running (apache in this case) and the debug working in real time on the preview of the website.
So if I have a variable printed, but I rewrite the value of it in the console it should update on the live site without the server or debug stopping.
Used the PHP example gitpod to demonstrate it kind of https://github.com/tetsuroba/Gitpod-PHP-Debug

I’m not quite sure how this should work in the GitPod environment but it works in local VSC environment.
Kind of like in this video https://youtu.be/LNIvugvmCyQ

Thanks in advance.

So I got your example working on the basis that I can see the variables set and stuff however the website does not render in real time as the response doesn’t seem to be sent until after the PHP script is run, however they way XDebug seems to work is that it must call to PHP I got your example running with php -S localhost:8080 -t public/ then starting the listen for XDebug thing in the debug menu, creating a breakpoint, and finally making a request it should then stop on the breakpoint letting you see the variables

Let me know if this helps!

We gave up. The environment is too limited. Not even email sending worked because of port limitation. No ssh.

@JesterOrNot

So I got your example working on the basis that I can see the variables set and stuff however the website does not render in real time as the response doesn’t seem to be sent until after the PHP script is run, however they way XDebug seems to work is that it must call to PHP I got your example running with php -S localhost:8080 -t public/ then starting the listen for XDebug thing in the debug menu, creating a breakpoint, and finally making a request it should then stop on the breakpoint letting you see the variables

I followed these directions exactly with the repo: https://github.com/tetsuroba/Gitpod-PHP-Debug/ and code execution does not halt on any breakpoints i set in /public/index.php

I don’t need the realtime rendering part of it, however I do need the debugger to work when the browser preview makes a request. Any advice?

UPDATE: looked like xdebug was failing in someway so I added a log and set xdebug.remote_connect_back = 1 in php.ini and got this when tailing the log (ip address masked for security):

xdebug error log:
[1832] Log opened at 2021-01-09 21:44:54
[1832] I: Checking remote connect back address.
[1832] I: Checking header ‘HTTP_X_FORWARDED_FOR’.
[1832] I: Remote address found, connecting to XX.XXX.X.XX:9000.
[1832] W: Creating socket for ‘XX.XXX.X.XX:9000’, poll success, but error: Operation now in progress (29).
[1832] E: Could not connect to client. :frowning:
[1832] Log closed at 2021-01-09 21:44:54

Hi @Devz3n,

I was able to reproduce the problem, and then managed it to fix it somehow. Here is what I did:

  1. Open https://gitpod.io/#https://github.com/tetsuroba/Gitpod-PHP-Debug
  2. Go to the Extensions panel in the left vertical menu
  3. Search for “PHP Debug”, and update the installed “PHP Debug” extension
  4. Refresh the Gitpod tab
  5. Run php -S localhost:8080 -t public/ in a Terminal, and open port 8080 in a preview
  6. Set a breakpoint somewhere in public/index.php
  7. Go to the Debug panel in the left vertical menu
  8. Click on the “Start” button next to “Listen for XDebug”
  9. Refresh the preview

This should stop on the breakpoint you set, and allow you to debug & step through the code.

Likely the “PHP Debug” extension is outdated in the example repo. I’ll see if I can update it it.

Update: I’ve sent a Pull Request to the example repo: https://github.com/tetsuroba/Gitpod-PHP-Debug/pull/1

ah thanks @jan! All good now. I had a feeling the issue was an outdated vscode extension file. I didn’t try that because I was unsure how to get the hash part in felixfbecker.php-debug@1.14.5:xEr6zDqY853IE2HQtLtXPA== , I couldnt find that anywhere. How did you get that new hash xEr6zDqY853IE2HQtLtXPA== ?

UPDATE:
I found an answer you gave on another post about the hash here.

@Devz3n Great news! :tada:

The easiest way to install or update extensions is via Gitpod’s “Extensions” panel (see left vertical menu bar in the IDE).

Simply:

  1. Search the extension’s name that you wish to install or update
  2. Click the install or update button
  3. Choose “install for this project” (not “install for username”)

This will automatically update your .gitpod.yml with the correct version & hash for the extension. Then you can simply commit & push that change.

(For what it’s worth, I believe the hash is a base64-encoded MD5 checksum of the .vsix binary, but it’s much easier to use the Extensions panel and let Gitpod update the extension hashes than to try and edit them manually.)

1 Like

Good to know. I am guessing the hash probably is not even required but a good idea to include for security reasons.
BTW, I updated the whole gitpod php debug system to use xdebug 3.0.2, works great.

2 Likes

Hey folks,

I have got myself a php application running inside a docker container on gitpod which I am trying to debug on request.
This has been working fine on my local system an phpstorm, but for now I am not having any luck on gitpod.
Whatever I have tried for now, the xdebug log gave me the following errors:

First try:

/tmp# tail -f xdebug.log 
[22] [Step Debug] WARN: Creating socket for 'host.docker.internal:9000', getaddrinfo: Invalid 
 argument.
[22] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9000 (through xdebug.client_host/xdebug.client_port) :-(
[22] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9000.
[22] [Step Debug] WARN: Creating socket for 'host.docker.internal:9000', getaddrinfo: Invalid argument.
[22] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9000 (through xdebug.client_host/xdebug.client_port) :-(
[22] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9000.
[22] [Step Debug] WARN: Creating socket for 'host.docker.internal:9000', getaddrinfo: Invalid argument.
[22] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9000 (through xdebug.client_host/xdebug.client_port) :-(
[22] Log closed at 2021-05-26 09:40:53.650261

Second try:

tail -f xdebug.log 
[22] [Step Debug] INFO: Connecting to configured address/port: localhost:9000.
[22] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[22] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[22] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9000 (through xdebug.client_host/xdebug.client_port) :-(
[22] [Step Debug] INFO: Connecting to configured address/port: localhost:9000.
[22] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[22] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[22] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9000 (through xdebug.client_host/xdebug.client_port) :-(
[22] Log closed at 2021-05-26 09:45:51.957805

Third try:

[23] [Step Debug] INFO: Checking remote connect back address.
[23] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[23] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 10.132.0.72:9000.
[23] [Step Debug] WARN: Creating socket for '10.132.0.72:9000', poll success, but error: Operation now in progress (29).
[23] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:9000. :-|
[23] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[23] [Step Debug] WARN: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[23] [Step Debug] ERR: Could not connect to debugging client. Tried: 10.132.0.72:9000 (from HTTP_X_FORWARDED_FOR HTTP header), localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[23] Log closed at 2021-05-26 09:50:19.628746

Any idea what I should my container it should use for the client_host ?
I have installed the latest php_debug extension within the gitpod, added port 9000 to my gitpod.yml

vscode:
  extensions:
    - felixfbecker.php-debug
ports:
  # App
  - port: 3000
    onOpen: ignore
  # Embed
  - port: 3001
    onOpen: ignore
  # API
  - port: 3010
    onOpen: ignore
  # Drupal
  - port: 3030
    onOpen: ignore
  - port: 3031
    onOpen: ignore
  # Drupal - Debug
  - port: 9000
    onOpen: ignore

And added the following config to .vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "Listen for XDebug",
          "type": "php",
          "request": "launch",
          "hostname": "0.0.0.0",
          "port": 9000,
          "pathMappings": {
              "/opt/drupal": "${workspaceRoot}"
          }
      }
  ]
}

Within the docker container, my application is located at /opt/drupal.

I am configuring xDebug during the build of my container like:

# Install & configure xDebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

What currently happens is when I set a breakpoint within the index.php, start the debug, open the page, it just jumps over the breakpoint and one of the above shown log messages appears.

Any idea what might go wrong?

I have been able to resolve this by setting the xdebug.client_host to the gitpods public ip address.
The public IP Address could be found by using: hostname -I on the host system.

Just make sure that the debug port is set to “public” within the gitpod GUI.

2 Likes

just to share if anyone wants to get xdebug.client_host directly working with host.docker.internal - as of now you can

  1. set experimentalNetwork: true in your .gitpod.yml,
  2. add extra_hosts : [ host.docker.internal:host-gateway] in your docker-compose.yml

that’s it! you can directly use host.docker.internal to refer to your gitpod host machine!

1 Like