Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Last active June 11, 2019 13:11
Show Gist options
  • Save gadelkareem/6b515dcc625f7fc0a74f9f214fb3292c to your computer and use it in GitHub Desktop.
Save gadelkareem/6b515dcc625f7fc0a74f9f214fb3292c to your computer and use it in GitHub Desktop.
Launch multiple PHP processes with a bash script
#!/usr/bin/env bash
OFFSET=0
LIMIT=200000
TOTAL=1000000000000000
MAX_PROCESS=10
echo "" > nohup.log
tail -f nohup.log &
TAIL_PID=$!
while [ $OFFSET -lt $TOTAL ]
do
echo "-- Initiating command with offset = $OFFSET"
nohup php SomeCommand.php $OFFSET >>nohup.log 2>&1 &
while [ $(ps -ef | grep -v grep | grep php | wc -l) -gt $MAX_PROCESS ]
do
printf "." && sleep 1
done
OFFSET=$[$OFFSET+$LIMIT]
done
while [ $(ps -ef | grep -v grep | grep php | wc -l) -gt 0 ]
do
printf "." && sleep 1
done
kill -s 9 $TAIL_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment