Trigger a php file with an exec command: how to see when process has stopped

Go To StackoverFlow.com

2

Given the following php code...

 <?php   
     exec('myscript.php');
     exec('finish.php'); 
?>

Is there a way to tell when myscript.php has stopped running?

I'd like to prevent finish.php from running until myscript.php is completed.

2012-04-04 21:48
by kylex


2

The exec() calls will block until the external job has completed. Unless you force one of the myscript call to run in the background, you'll never have finish.php running while myscript.php is.

2012-04-04 21:52
by Marc B


0

$output = shell_exec("myscript.php"); 

This is just a guess, but i'm willing to bet you'll see execution errors. This is likely because myscript.php does not have the needed bang line (#!/usr/bin/php) and +x flag to run.

* UPDATE *

Alternatively, it seems like you can just

include("myscript.php");
include("finish.php");

This will have the result you're looking for. If you actually want to execute these outside of the running process, see my above comment about bang line and making the scripts executable.

2012-04-04 21:52
by vicTROLLA


0

Is there a way to tell when myscript.php has stopped running?

If it runs finish.php the execution of myscript.php is finished. If it is a background process you could for example do something 'hacky' like creating a file when myscript.php is finished and check for that.

From the docs:

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.

2012-04-04 21:54
by PeeHaa


0

I would recommend you to use proc_open as it provides much more flexibility. You should also note that in the case of exec(), the second one will only be called after the first one terminates.

2012-04-04 21:57
by Kiryaka
Ads