Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDebug toggling optimizations #995

Open
er1z opened this issue Aug 22, 2024 · 4 comments
Open

XDebug toggling optimizations #995

er1z opened this issue Aug 22, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@er1z
Copy link

er1z commented Aug 22, 2024

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. :(

@er1z er1z added the enhancement New feature or request label Aug 22, 2024
@nickchomey
Copy link

Have you tried the xdebug command?

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

@er1z
Copy link
Author

er1z commented Aug 23, 2024

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

@nickchomey
Copy link

nickchomey commented Aug 23, 2024

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
Copy link
Author

er1z commented Aug 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants