启动PHP后台进程时出现问题
我最近创建了一个需要在后台运行的脚本。。我用这个代码来运行它启动PHP后台进程时出现问题,php,process,background,Php,Process,Background,我最近创建了一个需要在后台运行的脚本。。我用这个代码来运行它 function run_in_background($Command, $Priority = 0) { if($Priority) $PID = exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!"); else $PID = exec("nohup $Command 2> /dev/null &am
function run_in_background($Command, $Priority = 0) {
if($Priority)
$PID = exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!");
else
$PID = exec("nohup $Command 2> /dev/null & echo $!");
return($PID);
}
像这样使用它
run_in_background('curl http://www.mydomain.com/mypage.php',5);
不幸的是,它不是在后台运行
我还使用了:
shell_exec
而不是
exec
但它仍然不起作用。。我的设置有问题吗
注意:它不会在后台运行,但在加载页面时肯定会运行
感谢高级..在命令末尾放置一个
&
,告诉shell在后台运行进程
$PID = exec("nohup nice -n $Priority $Command 2> /dev/null & echo $! &");
我还提出并回答了一个类似的问题,您可以仔细查看,这可能会对您有所帮助:请查看此答案,似乎正是您想要的:
请小心使用此功能,并清楚地记录如何正确使用此功能。如果用户可以控制$Command或$Priority的值,那么您就有了命令注入漏洞。攻击者将能够使用与php运行相同的权限在web服务器操作系统上执行命令。