问题
i'm using php in apache on CentOS. i'm need to serve users, that they can delete big files by click. trying to use shell_exec. but its not run in the background. it runs and make the user wait.
my command :
$D_command="rm -rf videos/'$Mdelete'";
shell_exec($D_command);
thanks!
回答1:
ass & at the end of the command.
$D_command="nohup rm -rf videos/'$Mdelete' > /log/deletedfile.log 2>&1 &";
回答2:
$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
http://php.net/manual/en/function.shell-exec.php
回答3:
Try running
rm -rf videos/'$Mdelete' &
using exec
. The ampersand indicates to run to the background
回答4:
Try this:
popen($D_command, 'r')
回答5:
I know this is quite an old question, but I had the same issue, and this was the only working solution after trying and failing with exec
,shell_exec
, process_open
:
$process = popen("nohup $D_command > /dev/null 2> /dev/null & echo $!", 'r');
$pid = fread($process, 32);
来源:https://stackoverflow.com/questions/7221789/shell-exec-does-not-run-in-the-background-any-other-solution