Skip to content

Instantly share code, notes, and snippets.

@blendsdk
Created June 10, 2015 12:10
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 blendsdk/b7d2e722618daaa69ae0 to your computer and use it in GitHub Desktop.
Save blendsdk/b7d2e722618daaa69ae0 to your computer and use it in GitHub Desktop.
Start built-in PHP http server from next available port
#!/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