Skip to content

Instantly share code, notes, and snippets.

@frumbert
Created July 9, 2025 22:41
Show Gist options
  • Save frumbert/3573dc92983440af108fcdf083070eb7 to your computer and use it in GitHub Desktop.
Save frumbert/3573dc92983440af108fcdf083070eb7 to your computer and use it in GitHub Desktop.
pServe - instant local php webserver on a free port - shell/terminal script to run a php webserver at the current folder.
# add to your ~/.zshrc
function pserve() {
LOW_BOUND=49152
RANGE=16384
while true; do
CANDIDATE=$[$LOW_BOUND + ($RANDOM % $RANGE)]
(echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "http://127.0.0.1:$CANDIDATE" | pbcopy
echo "Copied server address to clipboard"
php -S 127.0.0.1:$CANDIDATE
break
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment