Run multiple PHP development servers in separate new screen sessions/tabs

Run several PHP development servers on different ports by sending commands to tabs in screen.

# screen_binary="screen"
# Start screen in detached mode with a session name.
screen -S "${screen_name}" -t "master" -d -m
# Wait for screen to be ready before opening new sessions.
sleep 1
# Create tabs and send commands to each.
for i in $(seq 1 "${server_count}"); do
    # Create tab.
    screen -S "${screen_name}" -X "screen" -t "my_screen_${i}"
    # Start development server in tab.
    (( port += $i ))
    command="php -S${port}"
    screen -S "${screen_name}" -p "my_screen_${i}" -X stuff "${command}"$'\n'
screen -r "${screen_name}"

The following commands will be run in separate tabs:

php -S
php -S
php -S
php -S
php -S
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment