#!/bin/bash # Launch php for debugging cli script, using vim as the debug client. # See http://stackoverflow.com/a/17885410/237059 for details on setup. #export XDEBUG_IDEKEY="idekey=vim_session" # For vim export XDEBUG_IDEKEY="idekey=netbeans-xdebug" # For netbeans function waitForSomeoneToOpenDebugPort { local port=9000 # TODO: Read this value from the vim php debugger script, somewhere in ~/.vim local debugHost=localhost # TODO: Likewise, get this from config local srchStr=":${port}" echo "Waiting for debug client to open port $port for connection from php:" while true; do # We just want to know if someone is listening on the debug port: ss -l4tpn | awk '/^LISTEN / {print $4}' | grep "$srchStr" >/dev/null if [[ $? -eq 0 ]]; then true return fi sleep 0.5 done } function errExit { echo "ERROR: $@" >&2 exit 1 } script=$1 if [[ -z $script ]]; then errExit "No script specified" fi if [[ ! -f $script ]]; then errExit "Can't find script: $@" fi while true; do echo "Ready to debug ($@). Press F5 in Vim, or Ctrl+C to exit:" waitForSomeoneToOpenDebugPort echo "Running php $@:" $(which php) "$@" result=$? echo " " echo ">>>> End of run, result code=$result <<<< " done