4

I have 55 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 php file that would execute all 55 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.

This thread: How to run multiple PHP scripts from CLI

suggests putting an & at the end of the command to run the command in the background, but using the xampp CLI this doesn't seem to do anything.

Any ideas greatly appreciated.

Brian

5
  • 1
    What operating system are you running? When you refer to the "xampp CLI", is this basically a DOS prompt running in Windows? Also, could you provide some sample output -- basically copy and paste the command-line, showing the prompts, and what you've typed (and gotten in response)? Commented Jul 5, 2011 at 3:52
  • It's likely possible to run php Script*.php. Commented Jul 5, 2011 at 3:52
  • The & command is specific to Unix/Linux. On windows you might have a chance with start command. Commented Jul 5, 2011 at 5:41
  • @zneak: no. The php CLI interpreter will only run the first php file passed to it on the command line. Although some programs (e.g. vim) will process each argument - it does so serially, not in parallel. Similar for xargs. Commented Jul 5, 2011 at 8:43
  • @symcbean, I missed the simultaneous part. Commented Jul 5, 2011 at 15:13

3 Answers 3

3

By mentioning XAMPP, I assume you are on windows. I think what you need is the start command. You probably need start php Script1.php. For more info, do a

start /?|more
Sign up to request clarification or add additional context in comments.

Comments

2

Linux

Apart from adding a &, you also need to redirect output to somewhere - otherwise your php process waits until the other process finished, because there could be more output:

exec('/path/to/program & > /dev/null 2>&1')

3 Comments

Thanks, this will help when I go to my production server, but I don't think it works under xampp (windows).
does it have a different effect if we put the & at the end of the command?
try it, then tell us.
1

You could use the php forking mechanism. Read about it here: http://php.net/manual/en/function.pcntl-fork.php

1 Comment

Looked into it, but the solution below was a little easier and did what I needed. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.