Last active
February 23, 2024 16:30
-
-
Save Zxce3/5917799a828d55043fbf90c076d035ca to your computer and use it in GitHub Desktop.
I don't know, it's just simple script
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 | |
# Script name: phloc | |
# Usage: | |
# phloc [port] [doc_root] | |
# port: port number to listen on (default: 8080) | |
# doc_root: document root (default: current directory) | |
# Description: | |
# Starts a PHP server on the specified port and document root. | |
# If no port is specified, the default port 8080 is used. | |
# If no document root is specified, the current directory is used. | |
# The script is intended to be used for local development. | |
if [ $# -eq 0 ]; then | |
port=8080 | |
else | |
port=$1 | |
fi | |
doc_root="." | |
if [ $# -eq 2 ]; then | |
doc_root=$2 | |
fi | |
while true; do | |
echo "Starting PHP server on port $port with document root $doc_root..." | |
php -S 0.0.0.0:$port -t $doc_root | |
# Check if the port is already in use | |
if [ $? -eq 0 ]; then | |
break | |
else | |
# Increment the port number and try again | |
echo "Port $port is already in use, trying port $((port+1))..." | |
port=$((port+1)) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment