0

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?

1
  • 2
    What errors did you get? Commented Oct 24, 2009 at 22:30

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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 :)

Comments

0

system('php file1.php')

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

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.