Skip to content

Instantly share code, notes, and snippets.

@hacfi
Created September 8, 2021 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hacfi/899301b3faf59424fac428803c56bd4a to your computer and use it in GitHub Desktop.
Save hacfi/899301b3faf59424fac428803c56bd4a to your computer and use it in GitHub Desktop.
Xdebug toggle switch
#!/bin/bash
# put into /usr/local/bin/xdebug and make it executable: chmod +x /usr/local/bin/xdebug
# Usage:
# xdebug # toggle...switch on or off, depending of the current state
# xdebug on # enable xdebug
# xdebug off # disable xdebug
# Adapt the path if you're not running PHP 8.0 installed via homebrew
XDEBUG_INI_PATH="/usr/local/etc/php/8.0/conf.d/ext-xdebug.ini"
function turn_off {
`sed -i 's/^zend_extension/#zend_extension/g' $XDEBUG_INI_PATH`
}
function turn_on {
`sed -i 's/^#zend_extension/zend_extension/g' $XDEBUG_INI_PATH`
}
CURRENT=`cat $XDEBUG_INI_PATH | grep "=xdebug"`
if [[ $CURRENT =~ ^#zend_extension ]];
then
echo 'Xdebug is currently off'
CHANGE_TO='on'
else
echo 'Xdebug is currently on'
CHANGE_TO='off'
fi
if [[ ${1+x} ]];
then
if [[ ! $1 =~ ^o(n|ff)$ ]];
then
echo "Invalid argument: $1. Valid arguments are \`on\` and \`off\`.";
exit 1
else
echo "Turning xdebug $1";
eval turn_${1}
fi
else
echo "Turning xdebug $CHANGE_TO"
eval turn_${CHANGE_TO}
fi
# Important: if you're running php-fpm make sure to send signal USR2 to the php-fpm process to reload the config to actually disable/enable xdebug on the webserver too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment