Last active
October 5, 2015 07:37
-
-
Save pateketrueke/2772520 to your computer and use it in GitHub Desktop.
My functions; with php's built-in web server
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
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