当负载大于x时,使用不同的(或修改的)htaccess文件


Use a different (or modified) htaccess file when the load is greater than x

不确定这是否可能,但如果加载大于x,我想使用不同的htaccess文件

我想要实现的是,当服务器上的负载高于40时,除我的IP外,向所有用户显示维护页面。

如果负载很高,我有手动包含的代码,但这涉及到我a)看到负载很高,b)在计算机附近编辑/FTP修改的htaccess文件。

当负载减少时,通常在30秒内进行更改,我必须将其恢复。

如果我不能使用不同的htaccess文件,那么根据负载进行检查。

许多谢谢。

这可能是不可能的,所以我想到的是一个php文件做以下…

如果加载大于20 mv .htaccess.bak和mv .htaccess.bak。2到。htaccess设置标志加载

如果load小于10并且flag设置为加载mv .htaccess到htaccess。2、mv .htaccess.bak to .htaccess设置flag为null

这(理论上)将允许在负载高时使用备份htaccess文件。

问题是把这个付诸实践:)

解决方案是在所有页面中添加一些php代码。

只是发了这个,以防将来有人需要它:)

    <php>
//Setup Variable:
$maxLoad = 40; //If the Load is occupying more than 2 cpus/cores
$time = 0; //0 means 1 minute, 1 means 5 minutes, 2 means 15 minutes.
$avgLoad = sys_getloadavg(); //Native PHP function to read Load Average of a Linux Server.
if ($avgLoad[$time] > $maxLoad) {
  //If the Load within $time is greater than the maximum numbers of CPUs specified into $maxLoad
   include ("maintenance.html");
   die();
}
</php>

然后将所有用户发送到维护页面,直到负载下降。