1

I' am calling sell script from my php code with

foreach ($some_array) {
     shell_exec(nohup $code); 
}

like above

I want all shell_exec call to work independent from mail process which is php execution that we call shell script

But It's not working as I expected all shell_executions start right after previous one completed

So how can I make this shell_exec calls as independent child process that they don't wait each others completation

Thanks in advance

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
soField
  • 2,536
  • 9
  • 36
  • 44
  • i found the solution here http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – soField Feb 14 '12 at 21:54

3 Answers3

0

Add the '&' to the end of the command you want to execute so it works in background.

acanimal
  • 4,800
  • 3
  • 32
  • 41
0

For a sequence of commands, enclose them within parentheses then append the & symbol but be sure to redirect stdout, stderr somewhere otherwise your script will hang waiting e.g.:

<?php

exec('( sleep 10; echo "finished" | mail ian@example.com ) &> /dev/null &');

?>

See http://us.php.net/manual/en/function.exec.php

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
-1

Send them to the background

shell_exec("nohup somecommand &");
                              ^---run job in background
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Doesn't work, at least in PHP 5.5. Try saving this simple script as `test.php` and running it: ``. You'll see a growing list of PHP processes in `ps -e`. – Mark Amery Aug 11 '14 at 15:47