0

I want to execute 2 scripts: s1 and s2. s2 must be executed after s1. The time of execution of s1 is 2800 seconds, and I need to execute s2 after s1. Should I put sleep(3000) in my php between them, or will the second one execute automatically after the first one?

I tried this:

exec('python s1 '); //time of execution is 2800s

sleep(3000); // i want to be sure that the first one is finished

shell_exec('php /home/Parik/s2.php');
Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
parik
  • 2,313
  • 12
  • 39
  • 67

1 Answers1

1

From the exec manual page:

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.

In short, PHP will wait for your python s1 command to finish before continuing.

Note that a execution time of 3000 seconds will most definitely time out without changing the default maximum execution time in the ini file. See How to increase maximum execution time in php.

Community
  • 1
  • 1
Pieter van den Ham
  • 4,381
  • 3
  • 26
  • 41