This little shell script allows you to enable Xdebug on demand when running a PHP script.
Xdebug is a powerful tool to debug PHP scripts, but is also known to be a performance killer: enabling it by default for CLI scripts will slow down all PHP commands such as Composer or PHPUnit. It is then recommended to not load the Xdebug extension at all for CLI. If you need to debug a script, enable the extension just for this script.
Note: the script was tested with PhpStorm only.
The script currently supports PHP 7.2+ and Xdebug 2+.
Copy the xdebug file in a directory that is part of your PATH
so it can be executed globally.
When you need to debug a PHP script, just prefix your command with xdebug
:
$ xdebug phpunit
$ xdebug php script.php