I ran into a problem with a composer script timing out on my machine because I had xdebug installed on the cli.
Now, I sometimes actually use xdebug on the cli, so I wanted a cli config that allowed xdebug be switched on and off, but defaults to off.
I found this global variable: PHP_INI_SCAN_DIR
I'm on Homebrew, so I made a new directory no-xdebug-conf.d
alongside /usr/local/etc/php/7.1/conf.d
directory, symlinking all the files that exist in /usr/local/etc/php/7.1/conf.d
from /usr/local/etc/php/7.1/no-xdebug-conf.d
to /usr/local/etc/php/7.1/conf.d
— except, of course ext-xdebug.ini
.
- You can find your configuration directory by executing
php -r "phpinfo();" | grep ini
.
If you just want xdebug off in the cli, add export PHP_INI_SCAN_DIR='/usr/local/etc/php/7.1/no-xdebug-conf.d'
to your ~/.bash_profile
.
export PHP_INI_SCAN_DIR='/usr/local/etc/php/7.1/no-xdebug-conf.d' function xdebug_cli_on() { unset PHP_INI_SCAN_DIR } function xdebug_cli_off() { export PHP_INI_SCAN_DIR='/usr/local/etc/php/7.1/no-xdebug-conf.d' }
Now the script executes in half the time!
I'll need to update this for switching versions of PHP, and I'll edit this post when I get around to that. Incremental improvements. Back to billable work for today!
- I discovered this doesn't work with PHPStorm, because PHPStorm appears to check for the presence of xdebug using the cli, so the debug icon is grayed out when xdebug for the cli is disabled. I'll be working on a fix for this issue shortly and editing this post.
References:
- Read about PHP_INI_SCAN_DIR here.