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