-1

I have a PHP script that runs on CRON and looks like this:

system("/usr/bin/php ".__DIR__."/main.php > ".__DIR__."/main_log.txt");

After main.php file does some processing, I'd like to execute two other scripts. Here is how I'm doing it inside main.php:

system("/usr/bin/php ".__DIR__."/script1.php > ".__DIR__."/script1_log.txt");
system("/usr/bin/php ".__DIR__."/script2.php > ".__DIR__."/script2_log.txt");

Since both script1.php and script2.php are doing very heavy processing (each may take about 5 hours), I'd like to know if these two calls are running simultaneously or if the next system call has to wait for the first one to finish before it can start?

My goal is for both scripts to run simultaneously.

farjam
  • 2,089
  • 8
  • 40
  • 77
  • Does the main one have to wait for both to complete? You might try threading. If the main script doesnt care about either, [you might try firing the two others as background processes](http://stackoverflow.com/questions/45953/php-execute-a-background-process) – castis Oct 15 '15 at 20:23
  • There are some code in main.php that needs to be run (takes ~ 15mins) before both script1 and script2 are called. Both script1 and script2 just open one single CSV file and process its data. One does the even rows, one does the odd rows. – farjam Oct 15 '15 at 20:28
  • trivial to test for your self, however yes they run simultaneously –  Oct 15 '15 at 20:33
  • @Dagon I tested it and they are not running at the same time, the second one runs after the first one is finished. – farjam Oct 16 '15 at 22:10
  • As long as output is either logged or disposed of exec calls are not blocking *Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.* –  Oct 16 '15 at 22:41

1 Answers1

0

Here is what I did to make them run at the same time:

exec("/usr/bin/php ".__DIR__."/script1.php > ".__DIR__."/script1_log.txt" & "/usr/bin/php ".__DIR__."/script2.php > ".__DIR__."/script2_log.txt");

farjam
  • 2,089
  • 8
  • 40
  • 77