Question

Not even sure if this is possible, but I would like to use a different htaccess file if the load is greater than x

What I am trying to achieve is the showing of a maintenance page to all users except my IP when the load on the server goes higher than say 40.

I have the code to manually include if the load is high, but this involves me a) seeing the load is high and b) being near a computer to edit / FTP the revised htaccess file.

Then when the load reduces, usually within 30 seconds of making the change I have to revert it back.

If I can't use a different htaccess file, then have a check in it depending upon the load.

Many thanks.

Was it helpful?

Solution 2

The solution to this was to add some php code to all pages.

Just posting this, incase anyone else needs it in the future :)

    <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>

This will then send all users to a maintenance page until the load drops.

OTHER TIPS

It is maybe not possible, so what I thought of was a php file to do the following...

if load is greater than 20 mv .htaccess to .htaccess.bak and mv .htaccess.2 to .htaccess set flag to load

if load is less than 10 and flag is set to load mv .htaccess to htaccess.2 and mv .htaccess.bak to .htacess set flag to null

This (in theory) would allow a backup htaccess file to be used if the load is high.

Problem is putting this into practice :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top