Shell_exec php with nohup

I think there are many similar posts, but I have not found a solution after the search.

Basically, I am trying to run two scripts in the background. When I run them on the command line, I see after calling my first script:

/usr/bin/nohup PHP .php > nohupoutput.log & echo $! 

I tried ...script.php > /dev/null & with the same result. I get:

 /usr/bin/nohup: ignoring input and redirecting stderr to stdout 

which I ignore and run the second. I noticed that it was hanging there, and pressing Enter returned me to machine:~folder>

 /usr/bin/nohup PHP 2.php > nohupoutput.log & echo $! 

Both scripts work. I tried then converting this to a shell_exec command and nothing works. I suspect that the ignoring input bit is causing difficulties, but I'm not sure. Despite this, the following does not work. It just freezes in the browser:

 $output = shell_exec('/usr/bin/nohup PHP .php > /dev/null &'); $output = shell_exec('/usr/bin/nohup PHP 2.php > /dev/null &'); 
+8
php shell-exec shellexecute exec nohup
source share
3 answers

Try:

 $output = shell_exec('/usr/bin/nohup PHP .php >/dev/null 2>&1 &'); 

Or:

 exec('/usr/bin/nohup PHP .php >/dev/null 2>&1 &'); 
+9
source share

This work:

 shell_exec('nohup /usr/bin/php path/to/script.php > output.txt &'); 
+2
source share
 this would help you dude.. <?php function execInBackground($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); } else { exec($cmd . " > /dev/null &"); } } //take note: to get your PHP_PATH, try looking at your phpinfo :) echo execInBackground("/usr/local/php53/bin/php 'example2.php'"); ?> 

This is my example work page: () **** http://affiliateproductpromotions.net/pop.php ***** ()

+2
source share

All Articles