0

I need to run several PHP scripts (they parse and retrieve some data through OAuth) in the right sequence, ONE AFTER ANOTHER, waiting for the previous to be completed (script2 needs data to be parsed after script1 and so on...).

For example:

script1.php -> COMPLETED -> script2-php -> COMPLETED -> script3.php -> ....

I'm calling scripts from mainscript.php with the following code:

<?php 

echo '<br /><br />SCRIPT 1<br /><br /> ';
include ("script1.php");

set_time_limit(0);
$seconds = 5; // HERE I PUT 5 SECONDS BECAUSE I THINK ITS THE RIGHT TIME TO RUN PARSING
sleep($seconds);

echo '<br /><br />SCRIPT 2<br /><br />';
include ("script2.php");

set_time_limit(0);
$seconds = 5; // HERE I PUT 5 SECONDS BECAUSE I THINK ITS THE RIGHT TIME TO RUN PARSING
sleep($seconds);

echo '<br /><br />SCRIPT 3<br /><br /> ';
include ("script3.php");

set_time_limit(0);
$seconds = 5; // HERE I PUT 5 SECONDS BECAUSE I THINK ITS THE RIGHT TIME TO RUN PARSING
sleep($seconds);

echo '<br /><br />SCRIPT 4<br /><br /> ';
include ("script4.php");

?>

So my question is: Does it make sense putting the set_time_limit and sleep into mainscript.php, or the INCLUDE function calls every script in the right sequence, in succession? Can you provide a solution, a suggestion?

SILminore
  • 509
  • 3
  • 10
  • 28
  • You're running a sleep command **after** you've run the first script. PHP is syncronous (doesn't run things simultaneously) in most cases (some PHP 5.3 functions have asynchronous callbacks, I think), and therefore there's no reason to do a `sleep` here. [For help how to do asynchronous PHP jobs, look here](http://stackoverflow.com/questions/124462/asynchronous-php-calls). – h2ooooooo Apr 13 '13 at 10:32
  • @h2ooooooo thanks, so my code is right, without sleep? and I'M SURE that scripts will load IN SUCCESSION? – SILminore Apr 13 '13 at 10:34
  • 1
    Yes, unless you're using asynchronous commands in the sub PHP files (such as `exec`, which, in certain cases, will not wait until the script is finished), then yes, you do not need the sleep commands, as the code will already have run when it gets to that point. – h2ooooooo Apr 13 '13 at 10:37

1 Answers1

1

There is no need for the sleep commands, php runs it in a sequence by definition.

The include command behaves as if you have added the lines of the included php files manually in a sequence in the main php file !

Lucian Depold
  • 1,999
  • 2
  • 14
  • 25