Ryan
Ryan

Reputation: 14649

How to write a PHP batch file that will execute a series of PHP files one after another?

I know I can set up a cron for each of the individual PHP files, but is there a way for a cron to run one PHP file that calls a list of files in a specific order. For example, It should only call the second file if the first file has completed.

Upvotes: 0

Views: 709

Answers (2)

Dany Khalife
Dany Khalife

Reputation: 1850

Try using php's system function.

You can find the doc here : http://www.php.net/manual/en/function.system.php

And you can use the return_value parameter and compare it against FALSE to check for failure

You can also use shell_exec (http://www.php.net/manual/en/function.shell-exec.php) which has almost the same effect

Upvotes: 3

Tusk
Tusk

Reputation: 723

If you would add a variable like $is_it_true = true when the script runs, and write ( $is_it_true ) ? include 'anotherfile.php':''

Then it'd do it. if you need more then just use it otherwise make it true by default, and make it false when error happens, and let it go inside if's.

Upvotes: -1

Related Questions