1

I have 5 php scripts need to be executed one after other. How can i create a single php/batch script which executes all the php scripts in sequence.

I want to schedule a cron which run that php file.

1
  • what do you have so far? Commented Nov 8, 2013 at 10:38

2 Answers 2

4
#!/path/to/your/php
<?php
include("script1.php");
include("script2.php");
include("script3.php");
//...
?>

Alternative

#/bin/bash
/path/to/your/php /path/to/your/script1.php
/path/to/your/php /path/to/your/script2.php
/path/to/your/php /path/to/your/script3.php
# ...

If your scripts need to be accessed via http:

#/bin/bash
wget --quiet http://path/to/your/script1.php > /dev/null 2>&1
wget --quiet http://path/to/your/script2.php > /dev/null 2>&1
wget --quiet http://path/to/your/script3.php > /dev/null 2>&1
# ...
Sign up to request clarification or add additional context in comments.

3 Comments

what about using exec?? instead of include as there may be some clashing of variables if i use include
If you keep your code clean there is no need to start more shell and php instances.
It's not a cleanliness issue ... it's a housekeeping issue, and it can be a pain in the neck making sure all your variables unique names if you don't want them treated globally, but that's what you have to do. I kind of hate this about the include function.
1

I did something for testing using the "wait" command, as it seems I just put wait between the calls to each script. I did a little test creating databases in php scripts, returning some records in a bash script, then updating with another php script, then another bash script to return the updated results and it seemed to work fine...

From what I have read, as long as the subscript doesn't call another subscript, the master script will wait if "wait" command is used between script calls.

Code is as below:

#!/bin/sh

/usr/bin/php test.php
wait

/bin/bash test.sh
wait

/usr/bin/php test2.php
wait

/bin/bash test2.sh
wait

echo all done

Hope it would execute all the php scripts in sequence.

Comments

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.