Last active
May 12, 2016 13:24
-
-
Save josue/4b567494ad45922b246100dd1f9af3ef to your computer and use it in GitHub Desktop.
xdebugger - Execute php file and outputs xdebug trace and script logs to file for further analyzing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
check_xdebug_installed () { | |
INSTALLED=`php -m | grep xdebug` | |
if [ "$INSTALLED" = "" ]; then | |
echo "PHP extention 'xdebug' must be installed." | |
exit 1 | |
fi | |
} | |
# define params | |
# | |
ME=`basename "$0" | sed 's/.sh//g'` | |
OPEN_TRACE=0 | |
PHP_FILE=$1 | |
if [ ! -f "$PHP_FILE" ]; then | |
echo "PHP file does not exist: $PHP_FILE" | |
exit 1 | |
fi | |
if [ "$1" = "-o" ]; then | |
OPEN_TRACE=1 | |
PHP_FILE=$2 | |
elif [ "$2" = "-o" ]; then | |
OPEN_TRACE=1 | |
PHP_FILE=$1 | |
fi | |
FILE_NAME=`echo "$PHP_FILE" | cut -f 1 -d '.'` | |
TRACE_FILE="$FILE_NAME.out" | |
LOG_FILE="$FILE_NAME.log" | |
OUTPUT_DIR="/tmp/xdebugger" | |
TRACE_DIR="$OUTPUT_DIR/cachegrinds" | |
LOG_DIR="$OUTPUT_DIR/logs" | |
TRACE_FILE_PATH="$TRACE_DIR/$TRACE_FILE" | |
LOG_FILE_PATH="$LOG_DIR/$LOG_FILE" | |
open_trace_file () { | |
if [ "$OPEN_TRACE" = "1" ]; then | |
echo -e "-------------------------------------------------------------------------------" | |
qcachegrind $TRACE_FILE_PATH | |
fi | |
} | |
run_xdebugger () { | |
mkdir -p {$TRACE_DIR,$LOG_DIR} | |
php -d xdebug.profiler_enable=On -d xdebug.profiler_output_dir=$TRACE_DIR -d xdebug.profiler_output_name=$TRACE_FILE $PHP_FILE > $LOG_FILE_PATH | |
echo | |
echo -e "Trace: $TRACE_FILE_PATH" | |
echo -e " Log: $LOG_FILE_PATH" | |
} | |
# run thru the actions | |
check_xdebug_installed | |
run_xdebugger | |
open_trace_file | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x /usr/local/bin/xdebugger
Usage (and output):
To open the xdebug trace output with
qcachegrind
GUI interface, simply call it with the-o
option.