Skip to content

Instantly share code, notes, and snippets.

@neochief
Last active September 2, 2019 10:52
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 neochief/ce9e16364e5ff04da7a7ccef1ce84434 to your computer and use it in GitHub Desktop.
Save neochief/ce9e16364e5ff04da7a7ccef1ce84434 to your computer and use it in GitHub Desktop.
Fast XDEBUG on/off switches
# Paste thing whole thing to your ~/.bashrc or ~/.zhrc
# Make sure all the variables on top point to correct
# destinations in your system. This all works under MacOS,
# bu should be easily adjusted for Ubuntu (you'll need to
# replace the PHP restart comands at the end).
#
# Quick reference:
#
# xon : enables xdebug, disables blackfire, disables opcache
# xoff : disables xdebug, enables blackfire, enables opcache
# bon : disables xdebug, enables blackfire, enables opcache
# boff : disables xdebug, disables blackfire, enables opcache
export PHP_VERSION="7.2"
export PHP_INI_DIR="/usr/local/etc/php/$PHP_VERSION"
export PHP_CONFIG_DIR="$PHP_INI_DIR/conf.d"
export PHP_XDEBUG_INI="$PHP_CONFIG_DIR/ext-xdebug.ini"
export PHP_BLACKFIRE_INI="$PHP_CONFIG_DIR/ext-blackfire.ini"
export PHP_OPCACHE_INI="$PHP_CONFIG_DIR/ext-opcache.ini"
function xdebug_on {
if grep -q "\#zend" "$PHP_XDEBUG_INI"; then
sed -i '' -E 's/#*zend_extension/zend_extension/g' "$PHP_XDEBUG_INI";
restart="1";
fi
}
function xdebug_off {
if ! grep -q "\#zend" "$PHP_XDEBUG_INI"; then
sed -i '' -E 's/#*zend_extension/#zend_extension/g' "$PHP_XDEBUG_INI";
restart="1";
fi
}
function opcache_on {
if grep -q "\#zend" "$PHP_OPCACHE_INI"; then
sed -i '' -E 's/#*zend_extension/zend_extension/g' "$PHP_OPCACHE_INI";
restart="1";
fi
}
function opcache_off {
if ! grep -q "\#zend" "$PHP_OPCACHE_INI"; then
sed -i '' -E 's/#*zend_extension/#zend_extension/g' "$PHP_OPCACHE_INI";
restart="1";
fi
}
function blackfire_on {
if grep -q "\#extension" "$PHP_BLACKFIRE_INI"; then
sed -i '' -E 's/#*extension/extension/g' "$PHP_BLACKFIRE_INI";
restart="1";
fi
}
function blackfire_off {
if ! grep -q "\#extension" "$PHP_BLACKFIRE_INI"; then
sed -i '' -E 's/#*extension/#extension/g' "$PHP_BLACKFIRE_INI";
restart="1";
fi
}
function xon {
restart="0";
xdebug_on;
blackfire_off;
opcache_off;
if [ "$restart" = "1" ]; then
sudo brew services restart php@"$PHP_VERSION";
fi
}
export xon
function xoff {
restart="0";
xdebug_off;
blackfire_on;
opcache_on;
if [ "$restart" = "1" ]; then
sudo brew services restart php@"$PHP_VERSION";
fi
}
export xoff
function bon {
restart="0";
xdebug_off;
blackfire_on;
opcache_on;
if [ "$restart" = "1" ]; then
sudo brew services restart php@"$PHP_VERSION";
fi
}
export bon
function boff {
restart="0";
xdebug_off;
blackfire_off;
opcache_on;
if [ "$restart" = "1" ]; then
sudo brew services restart php@"$PHP_VERSION";
fi
}
export boff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment