dunglas / frankenphp

šŸ§Ÿ The modern PHP app server
https://frankenphp.dev
MIT License
6.67k stars 220 forks source link

XDebug toggling optimizations #995

Open er1z opened 3 weeks ago

er1z commented 3 weeks ago

Describe you feature request

Is your feature request related to a problem? Please describe. Reloading container only to toggle XDebug is rather expensive because it involves restarting whole container and its script to detect all the initialization process. XDEBUG_MODE=debug docker composeā€¦ IMHO is not the optimal way to do so. Also, all the sessions are being destroyed, temporary files discarded what makes development even more frustrating.

Describe the solution you'd like I'd like to have a single command to toggle debugging mode, without a need to restart whole container.

Describe alternatives you've considered Tried to do on my own by altering php.ini files but changes are not taken into the consideration for reload. Tried touching Caddyfile to trigger reload and even frankenphp reload but SAPI configuration is kept as is.

Will be glad to see a DX improvement for this. Mounting /tmp as a volume is a bit dirty. :(

nickchomey commented 2 weeks ago

Have you tried the xdebug command?

https://ddev.readthedocs.io/en/stable/users/usage/commands/#xdebug

er1z commented 2 weeks ago

@nickchomey, how does it relate to FrankenPHP and reloading Caddy? Checked the script that it executes and it's completely beyond my question.

nickchomey commented 2 weeks ago

Hah! I'm so sorry, I was working on some stuff in DDEV and somehow thought that this issue was in that repo when I saw this just before going to sleep. I was even looking just now in the DDEV repo for this issue and confused why I couldn't find it.

Please ignore my comment (though, do check out DDEV, it is fantastic for php local development - though doesn't yet support caddy or frankenphp)

er1z commented 2 weeks ago

So far, I ended up with something dirty AF:

First, removed all XDEBUG_MODE references from compose override file.

Second (as I use Makefile), added two commands:

xdebug-enable:
    docker compose exec php sh -c 'echo "xdebug.mode=debug" > /usr/local/etc/php/conf.d/xdebug.ini && kill $$(pidof frankenphp)'

xdebug-disable:
    docker compose exec php sh -c 'echo "xdebug.mode=off" > /usr/local/etc/php/conf.d/xdebug.ini && kill $$(pidof frankenphp)'

Then I updated a Dockerfile with killing XDEBUG_MODE environment variable (as it's being used as the one with the highest priority). Also, added (for dev image):

COPY --link frankenphp/conf.d/xdebug.ini $PHP_INI_DIR/conf.d/

And finally, updated CMD:

CMD ["sh", "-c", "while true; do frankenphp run --config /etc/caddy/Caddyfile --watch; echo 'frankenphp crashed with exit code $?'; sleep 1; done"]

Result: blazing fast toggling of XDebug and session is continued what improves DX (no need to re-login, re-upload, etc).

Dunno if it's a legit way to do so, but at least for me works. If @dunglas is interested in that way, will create a PR.