Skip to content

Instantly share code, notes, and snippets.

@pquerner
Forked from dbalabka/.phpdebug
Created January 7, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pquerner/91f65a32886120ecf38f to your computer and use it in GitHub Desktop.
Save pquerner/91f65a32886120ecf38f to your computer and use it in GitHub Desktop.
PHP CLI debugging helper console commands with PhpStorm, NetBeans support
# Installation steps:
# 1. Put these lines into ~/.bashrc;
# 2. Script will try to autodetect your machine IP where runs IDE or use 127.0.0.1 otherwise.
# If automatic detection doesn't work for you, set ip directly via IDE_IP enviroment variable:
# $ export IDE_IP=1.2.3.4
# 3. Change ports if it not same as default (see local variables zend_debugger_config and xdebug_config);
# 4. Change IDE specific configuration: serverName, idekey (see local variables php_ide_config and xdebug_config)
# 5. Run: source ~/.bashrc
# Usage:
# 1. After installation use phpdebug/phpdebugoff commands to start/stop debugging:
# $ phpdebug
# $ php ./script1_to_debug.php
# $ php ./script2_to_debug.php
# $ phpdebugoff
# 2. Or simply use instead of php command to debug only one script
# $ phpdebug -dmemory_limit=1G ./script_to_debug.php
# User specific aliases and functions
function _phpdebug() {
# For Zend debugger
# Set special EVN variables (don't forget to change "debug_host" and "debug_port")
local zend_debugger_config="start_debug=1&debug_stop=0&debug_fastfile=1&debug_covere=1&use_remote=1&send_sess_end=1&debug_session_id=2000&debug_start_session=1&debug_port=10137"
# For Xdebug
# Set special EVN variables.
# PHPSTORM is default idekey key. It must be same like in PhpStorm -> Settings -> PHP -> Debug -> DBGp Proxy
local xdebug_config="idekey=PHPSTORM"
# case for remote debugging (don't forget to change "remote_host" and "remote_port")
#local xdebug_config="idekey=PHPSTORM remote_host=1.2.3.4 remote_port=9000"
# For PhpStorm
# Same for Xdebug and Zend Debugger
# PhpStorm server config name is placed in Settings -> PHP -> Servers
local php_ide_config="serverName=localhost"
# try to autodetect IP if global variable IDE_IP not set
if [ -z ${IDE_IP+x} ]; then
if [ -z "$SSH_CLIENT" ]; then
IDE_IP="127.0.0.1";
else
IDE_IP=$( echo $SSH_CLIENT | sed s/\ .*$// );
fi
fi
zend_debugger_config="${zend_debugger_config}&debug_host=${IDE_IP}"
if [ "$*" == "" ]; then
export QUERY_STRING="$zend_debugger_config"
export XDEBUG_CONFIG="$xdebug_config_"
export PHP_IDE_CONFIG="$php_ide_config"
else
PHP_IDE_CONFIG="$php_ide_config" XDEBUG_CONFIG="$xdebug_config_" QUERY_STRING="$zend_debugger_config" php $*
fi
}
alias phpdebug="_phpdebug"
alias phpdebugoff="unset QUERY_STRING && unset PHP_IDE_CONFIG && unset XDEBUG_CONFIG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment