Question

I need to be able to put the site in 'maintenance mode'. So I'm using a cheap hack like this one in app.php (the original app.php was moved to app.php.bak):

<?php

$key = 123;

if(isset($_GET['skip_maintenance_key']) && $_GET['skip_maintenance_key'] == $key) {
    setcookie('skip_maintenance_key', $key);
}

if(isset($_COOKIE['skip_maintenance_key']) && $_COOKIE['skip_maintenance_key'] == $key) {
    include 'app.php.bak';
    // placeholder
} else {
    //header('Cache-Control: public, maxage=30');
    header('Status: 503 Service Unavailable');
    include 'html/error/503.html';
}

The problem is that as soon as I hit a page that uses http cache, the page gets cached by intermediaries like Cloudflare or my own proxy and it begins to be served to everyone.

So what I would like to do is somehow disable http cache globally during maintenance, maybe adding a line of code in // placeholder?

Any ideas?

Was it helpful?

Solution

I read Fabien saying (in a pull request that got rejected) that this should be handled by the web server. So I changed my maintenance script to modify the server config instead of the framework.

The problem was the server was not able to remove the cache headers. But then I found the NginxHttpHeadersMoreModule which worked just fine, so problem solved.

OTHER TIPS

if you have access to httpd.conf you could add:

Header set Cache-Control no-cache
Header set Expires 0

or if not, take a look to this tutorial

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