Reputation: 5871
The scenario:
Every approach I try seems to result in PHP still waiting for the shell script to finish executing. Approaches I've tried:
nohup ./script.sh > run.log &
nohup ./script.sh > run.log 2>&1
nohup ./script.sh > run.log 2>&1 &
./script.sh &
./script.sh > run.log 2>&1
./script.sh > run.log &
I think there's something really obvious I might be missing. Any ideas?
Upvotes: 1
Views: 2291
Reputation: 3541
Your number 5 approach is close but you need to combine it with 6 like this
shell_exec("/script.sh > run.log 2>&1 &");
Or redirect to /dev/null like this
shell_exec("/script.sh > /dev/null 2>/dev/null &")
It appears that the PHP development server cannot fork off commands properly. Using a real web server like Apache or NGinx will resolve the issue.
Upvotes: 1
Reputation: 910
Have you tried shell_exec ?
You might be interested in this post : Is there a way to use shell_exec without waiting for the command to complete?
Upvotes: 1
Reputation: 520
I think you could achieve this by starting a screen
instance with the script:
screen -d -m 'bash ./script.sh > run.log'
Upvotes: 2