Alright, first off.. This is my first StackOverflow post, so please let me know if anymore information is needed or if anything is done incorrectly.
I am working on a website that has a REST API on the same server and am trying to debug it using Docker and Xdebug. My php.ini has the following settings for Xdebug:
# Xdebug 3
xdebug.mode=debug
# Client stuff
xdebug.discover_client_host=1
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey="netbeans-xdebug"
# Making sure we have some time
xdebug.connect_timeout_ms = 6000
;xdebug.log_level : 0 Criticals, 1 Connection, 3 Warnings, 5 Communication, 7 Information, 10 Debug Breakpoint
xdebug.log_level=7
xdebug.log=/var/log/xdebug/xdebug.log
# Some error and log settings
xdebug.force_display_errors=1
xdebug.show_error_trace=1
xdebug.show_exception_trace=1
xdebug.show_local_vars=0
The webserver part of the compose file has the following:
# This is the container for the Apache server
web:
# The location of the Dockerfile
build:
context: './bin/php'
# A file containing sensitive information
env_file: ".env"
# The name for this container
container_name: "server"
# If anything goes wrong, restart the web server
restart: "always"
# Using both port 80 on the host and the container
ports:
- "80:80"
# We want the database to be started before the server can start
depends_on:
- database
volumes:
# The 'web' directory will be mapped to the container directory "/var/www"
- ./web:/var/www
- ./settings.conf:/var/settings.conf
# These are config files mapped to the VMs config files
- ./config/php/php.ini:/usr/local/etc/php/php.ini
- ./config/vhosts:/etc/apache2/sites-enabled
# These are log directories mapped to the VMs log directories
- ./logs/apache2:/var/log/apache2
- ./logs/xdebug:/var/log/xdebug
environment:
# Settings for the Apache webserver
APACHE_DOCUMENT_ROOT: /var/www
# Settings for phpMyAdmin
PMA_PORT: 8080
# Settings for the MySQL database
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: database
HOST_MACHINE_MYSQL_PORT: 3306
# Settings for XDEBUG
XDEBUG_CONFIG: "client_host=host.docker.internal remote_port=9003"
extra_hosts:
- "host.docker.internal:host-gateway"
The Dockerfile for the website is build using a PHP:8.2-apache image, installing Xdebug and more. The host machine runs on Windows 11, the docker image on Apache. I'm using NetBeans on the host machine and map the project directory to the docker image.
When I'm not debugging, the website works properly and everything goes fine. When I'm using Xdebug, everything connects well, breakpoints hit and I can step through the code. As soon as it hits the curl_exec line to do a REST API call on the same server, everything hangs. I've checked the logs and there are no errors whatsoever... Even when I disable and delete all breakpoints, it just hangs.
When I use WAMPServer, the debugging works just fine. I've been looking at the differences between my Docker environment and the WAMPServer environment and they should be pretty much the same. So, I'm not sure what I am missing. When I use Postman to send the same REST API call, it gives no errors and doesn't hang either, but the breakpoints can't be found due to a mapping issue. I don't think it's related to the hanging though.
I've tried different settings, but most of those were for Xdebug 2 (using xdebug.remote_auto_start and such) and thus no longer work for Xdebug 3.
curl_exec)? In general, I'd think that thiscurl_execis awaiting for the debug session, but I'm not sure if NetBeans supports more than 1 active debug session (PhpStorm does). But then, if the same works in WAMPServer environment, then this might not be the cause... Anyway, Xdebug log should show such sub requests if it's configured to debug every single request (or sees the "debug me" param)...xdebug.start_with_request = yes-- so Xdebug tries to debug every single request, regardless of the "debug me" flag (a cookie, request parameter or env variable). Try returningxdebug_info();output for those requests (main and API) and see what might be different there -- good starting point.curl_execbut just hangs. Once I terminate the debugging session, the Xdebug log gets updated with the remaining information. I've tried VS Code just to be sure, and over there everything just works as intented. So for now I'll continu with VS Code, but I am very interested to see whatxdebug_info()has to say!maxConnectionsoption as far as I understand)