Created
June 10, 2015 12:10
-
-
Save blendsdk/b7d2e722618daaa69ae0 to your computer and use it in GitHub Desktop.
Start built-in PHP http server from next available port
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 | |
IPADDR=127.0.0.1 | |
STARTPORT=8000 | |
ENDPORT=9000 | |
found=false | |
for (( port = $STARTPORT ; port <= $ENDPORT ; port++ )); do | |
printf "Checking $port\r"; | |
if ! nc -z -w5 $IPADDR $port | |
then | |
found=true; | |
break; | |
fi | |
done | |
if $found | |
then | |
gnome-open http://$IPADDR:$port & | |
php -S $IPADDR:$port -t . | |
else | |
echo "No empty ports found!"; | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment