2

I want to run a shell script in php, but this shell script takes a long time to execute (it has sleep in it), I don't want the web server to block when executing this script. I tried exec() and shell_exec() in php but the server stops until the shell script finishes!

I thought of doing fork in the shell script itself but I don't know how to do that. I just want the php script to call this shell script and continue working, I'm not waiting any result from the script.

I tried running the shell script in the background with & still get blocking :( Any help is highly appreciated.

Reem
  • 1,439
  • 2
  • 18
  • 21
  • 2
    Have a look here: http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – Mike Jun 29 '10 at 08:59
  • Or here: [Are there any alternatives to shell_exec and proc_open in PHP?](http://stackoverflow.com/questions/2657412/are-there-any-alternatives-to-shell-exec-and-proc-open-in-php) – Gordon Jun 29 '10 at 09:10

1 Answers1

2

I solved the problem by adding

"> /dev/null 2>/dev/null &"

after the script name to the shell_exec() php function

Thanks

Reem
  • 1,439
  • 2
  • 18
  • 21