shell_exec does not run in the background, any other solution?

大兔子大兔子 提交于 2019-12-10 15:17:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!