1

My dev setup includes PHP 8 and Xdebug 3 in a docker container for a Symfony project.

Currently I use xdebug.start_with_request=yes, but I don't like the performance impact that has.

How do I start an Xdebug session on demand for Symfony console commands?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
simon.ro
  • 2,984
  • 2
  • 22
  • 36

1 Answers1

2

Set Xdebug mode to off(xdebug.mode = off; in your settings), set the environment variable XDEBUG_MODE = debug only for the script you are executing:

XDEBUG_MODE = debug bin/console run:my:command

Now Xdebug will only be enabled while you execute bin/console run:my:command.

You mention that you are executing your scripts inside a docker container, but that shouldn't change things too much. You could pass the environment variable in the docker exec call with the --env argument.

yivi
  • 42,438
  • 18
  • 116
  • 138
  • thanks @yivi! Setting the `XDEBUG_MODE ` manually is probably the best i can do. But it actually should be `XDEBUG_MODE=debug bin/console run:my:command` (without ;) – simon.ro Feb 16 '21 at 12:32
  • 1
    Fixed it for you. When the env vars are actually populated or not is something that can be confusing sometimes. I had better luck with `;`, and I'm [not the only one](https://stackoverflow.com/questions/10856129/setting-an-environment-variable-before-a-command-in-bash-is-not-working-for-the). I guess it depends exactly what are you running and where do you need the env var to be available. – yivi Feb 16 '21 at 12:35