views:

172

answers:

3

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... I'm not sure how to do this... if someone can help, that'd be great...

A: 

You can run it from 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");

?>

Havent tested, but it should work :)

Whitey
A: 

system('php file1.php')

Or, just use a shell script if on *nix.

DigitalRoss
+2  A: 

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.

Adam Wright
Even better, make a function that includes the files. To prevent variables from being reset. This method of course has the disadvantage that if one script dies, so does the rest
antennen