Skip to content

Instantly share code, notes, and snippets.

@codfish codfish/xdebug-hack.md
Last active Dec 19, 2017

Embed
What would you like to do?
Xdebug Hack

Xdebug tends to slow down a lot of things. Here's a hack to unload the extension by default but load it whenever it's needed (for instance, when generating php code coverage.

Prevent Xdebug from loading by default

If you use brew to install php 7, should be here: /usr/local/etc/php/<version>/conf.d/ext-xdebug.ini. Edit that file (replacing <version> with whatever version of php you're using) and comment out the line that begins with zend_extension. The code examples here assume 7.0.

;zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"

If you don't use brew, do the exact same thing, but you'll need to find where your xdebug config is. Try running

vim `php -i | grep 'ext-xdebug.ini'`

Update bash aliases

Use bash aliases to allow you to load xdebug if you run php directly:

alias php='php -dzend_extension=/usr/local/opt/php70-xdebug/xdebug.so'
alias phpunit='php $(which phpunit)'

If you have any php cli's that run anything that requires Xdebug (test coverage, etc), you may need to run them through your php alias to make sure they run with xdebug enabled. But now everything else will run with is disabled, speeding things up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.