The code:
exec('ps aux |grep tweet',$output,$return_var);
if(count($output)>0){
exec('php ' . DOCROOT . 'gremlins/tweet_gremlin.php &');
file_put_contents(DOCROOT . 'gremlins/tweet_gremlin.log', date('r') . ' Tweet Gremlin was not running. Starting now...');
}
In my head, this code makes sense but it just causes the browser to loop indefinitely. What I’m trying to do is check to see if tweet_gremlin.php is running, if its not running, start it. DOCROOT is a constant defined earlier in the code.
You could use:
The
grep -vpart removes thegrepprocess from the list.Also, to execute a background process with
execand such, you will be need to redirect the output, otherwise your script will hang until the process has finished. Per example: