I have 50 php files that I would like to run simultaneously from the command line. Right now, I am running them in multiple CLI windows using the code:
php Script1.php
I would like to be able to call one single script file that would execute all 50 php files simultaneously. I have been reading about how to make the command line not wait for the output, but I can't seem to make it work.
I am new to both MAC and Scripting - maybe I don't need a script? Is there another mac based solultion that can do this without me having to open 50 separate terminal windows?
You can just add ampersand '&
' to separate each command:
php script1.php & php script2.php & php script3.php ...
This ampersand symbol will tell the shell to run command on background.
To check the output, you can redirect it to a file:
php script1.php > script1.log.txt & php script2.php > script2.log.txt
And you can just do a tail
on it to read the log:
tail -f script1.log.txt
If you script is nicely numbered from 1 to 50, you can try the following in a .command
file:
i=1;
while [ $i -lt 51 ]
do
osascript -e 'tell app "Terminal"
do script "php Script$i.php"
end tell' &
i=$[$i+1]
done
This should open 50 separate terminal windows each running script{$i}.php
You could also run them at the same time but not in the background.
php test1.php; php test2.php;
I don't know why you would want to "interact" with the script after its running.