我知道我可以使用php运行bash命令,但它会超时,我需要它继续运行。所以我想要完成的是让这个站点在我的服务器上调用我的bash文件,而不是在php中实际运行它
答案 0 :(得分:0)
在php脚本的开头使用此代码:
<?php
ini_set('max_execution_time', 0);
...
0
表示永远运行/直到脚本结束。或者以秒为单位设置合理的限制。
答案 1 :(得分:0)
这是我用来通过php运行bash脚本的方法:
<?php
set_time_limit(0); // run for unlimited time
ignore_user_abort(1); //runs even if the user closes the browser/shell session
$command = $_GET['c'];
$pass = $_GET['p'];
if($p == "my password" & !EMPTY($command)){
switch ($command){
case "dothis":
$command = "sh /path/to/dothis.sh";
break;
case "dothat":
$command = "sh /path/to/dothat.sh";
break;
default:
$command = "";
break;
}
shell_exec("nohup $command &");
// nohup: run a command immune to hangups, with output to a non-tty
}
?>
示例:http://www.my-site.com/bash.php?c=dothis&p=mypass
您也可以通过apache
.htaccess/.htpasswd
对目录进行密码保护,然后您可以使用以下方式访问该脚本: