Created
July 9, 2025 22:41
-
-
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.
This file contains hidden or 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
# 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