Reputation: 807
I have a series of PHP scripts that I want to run in a particular order. I tried using
<?php
exec('file1.php');
exec('file2.php');
exec('file3.php');
?>
to accomplish this, but just got a series of errors. If I run them from the command line, they all work fine. How to fix this problem?
Upvotes: 0
Views: 1637
Reputation: 68
You can run it from the command line from your scripts, assuming you have root access.
Example:
<?php
system("php -f path/to/your/script/file1.php");
system("php -f path/to/your/script/file2.php");
system("php -f path/to/your/script/file3.php");
?>
I haven't tested it, but it should work :)
Upvotes: 0
Reputation: 49376
If the state of each script is well isolated (i.e. not clashing function/class names and global variables), you can just include each of them in turn.
include("file1.php");
include("file2.php");
...
This will also ensure you don't spin up multiple PHP interpreters.
Upvotes: 2
Reputation: 146073
system('php file1.php')
Or, just use a shell script if on *nix.
Upvotes: 0