Xdebug: off by default on CLI, auto-triggered on web only

Loading xdebug.mode=debug at all times made every drush/composer command
noticeably slower, since Xdebug hooks every function call as soon as the
mode is active regardless of whether a debugger connects. Split the config
per-SAPI instead: CLI defaults to xdebug.mode=off (opt in with the new
xdebugon/xdebugoff aliases or XDEBUG_MODE=debug XDEBUG_TRIGGER=1), while
php-fpm keeps xdebug.mode=debug + start_with_request=yes so browser
requests still auto-connect with no trigger needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 14:09:05 +02:00
co-authored by Claude Sonnet 5
parent 0a45ff2d10
commit 8040225ace
2 changed files with 37 additions and 1 deletions
+13 -1
View File
@@ -41,6 +41,13 @@ COPY ./rsyslog-drupal.conf /etc/rsyslog.d/drupal.conf
# ENTRYPOINT ["sh", "-c", "service rsyslog start ; tail -f /dev/null"]
COPY ./php-custom.ini /usr/local/etc/php/conf.d/php-custom.ini
# Xdebug: off by default on CLI (drush, composer) — mode=debug alone still hooks every
# function call and is what makes CLI commands slow, even with start_with_request=trigger.
# Use `XDEBUG_MODE=debug XDEBUG_TRIGGER=1 drush ...` (see xdebugon/xdebugoff aliases) to debug a CLI run.
# FPM loads an extra ini dir that restores mode=debug + start_with_request=yes for web requests.
RUN printf "xdebug.mode=off\nxdebug.start_with_request=trigger\n" > /usr/local/etc/php/conf.d/zz-xdebug-cli.ini && \
mkdir -p /usr/local/etc/php/fpm-conf.d && \
printf "xdebug.mode=debug\nxdebug.start_with_request=yes\n" > /usr/local/etc/php/fpm-conf.d/zz-xdebug-fpm.ini
# COPY ./php-fpm-custom.conf /usr/local/etc/php-fpm.d/php-fpm-custom.conf
@@ -64,6 +71,11 @@ RUN if getent group ${USER_GNAME} ; then groupdel ${USER_GNAME}; fi &&\
COPY ./bashrc /home/${USER_UNAME}/.bashrc
COPY ./inputrc /home/${USER_UNAME}/.inputrc
# /home/${USER_UNAME} is a persistent named volume, so files COPYed there only apply on
# first volume creation. Put the xdebug aliases in /etc/bash.bashrc instead, which is part
# of the image and always sourced by interactive shells (docker exec, ssh).
RUN printf "\n# Xdebug is off by default on CLI for speed (see zz-xdebug-cli.ini).\nalias xdebugon='export XDEBUG_MODE=debug XDEBUG_TRIGGER=1'\nalias xdebugoff='unset XDEBUG_MODE XDEBUG_TRIGGER'\n" >> /etc/bash.bashrc
# https://github.com/ProgDroid/composer_update_autocomplete
RUN mkdir /home/${USER_UNAME}/.bin
COPY ./composer_update_autocomplete /home/${USER_UNAME}/.bin/composer_update_autocomplete
@@ -82,7 +94,7 @@ EXPOSE 22
# https://stackoverflow.com/questions/36964652/ssh-in-docker-container-causes-http-404
# use \n to make the content into multiple lines
RUN printf "whoami\nphp-fpm -D\n/usr/sbin/sshd -D" >> /start.sh
RUN printf "whoami\nPHP_INI_SCAN_DIR=/usr/local/etc/php/conf.d:/usr/local/etc/php/fpm-conf.d php-fpm -D\n/usr/sbin/sshd -D" >> /start.sh
RUN chmod +x /start.sh
CMD ["/start.sh"]