Skip to content

Instantly share code, notes, and snippets.

@pateketrueke
Last active October 5, 2015 07:37
Show Gist options
  • Save pateketrueke/2772520 to your computer and use it in GitHub Desktop.
Save pateketrueke/2772520 to your computer and use it in GitHub Desktop.
My functions; with php's built-in web server
rand_port(){
port=$(( 1234+( $(od -An -N2 -i /dev/random) )%(1023+1) ))
while :
do
(echo >/dev/tcp/localhost/$port) &>/dev/null && port=$(( 1234+( $(od -An -N2 -i /dev/random) )%(1023+1) )) || break
done
echo "$port"
}
phpmin(){
for file in `find . -type f -not -path "*.git*" | grep "\\.php"`; do
php -w $file > "$file.tmp"
mv "$file.tmp" $file
done
}
phps(){
root=$1
port=$2
prefix=''
if [ ! $root ] ; then
root="$(pwd)"
fi
if [ ! $port ] ; then
port="$(rand_port)"
fi
if [ $port = 80 ]; then
prefix='sudo '
fi
server="$prefix php -S 0.0.0.0:$port -t $root"
eval $server
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment