parik parik - 1 year ago 87
PHP Question

order of executing shell_exec in php

I want to execute 2 scripts:

must be executed after
The time of execution of
is 2800 seconds, and I need to execute
. Should I put
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');

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download