Reputation: 1226
I would like to add a "maintenance mode" to a Symfony application - a simple boolean configuration which I set during runtime. Controllers (or possibly the front controller) can check this value and either; process the request as normal, or return HTTP 503 and a friendly message.
I can think of 3 possible solutions:
parameters.yml
This is the logical place to put a configuration, but it gets cached by the Symfony app and using maintenance mode may require a cache:clear
to take effect. I would like to avoid this!
A custom configuration file It could look for the existence of "maintenance.flag" or read a setting in a custom file. This is adding an extra disk operation for every controller visit and feels inefficient.
An environment variable
It could use getenv()
to look for the existence and value of a maintenance mode environment variable. This feels like an efficient approach and I can't think of any negatives.
Has anyone found an efficient way to achieve this kind of feature? Am I re-inventing the wheel?
Upvotes: 3
Views: 401
Reputation: 17926
as you asked about runtime and i suggested to use webserver conf have a look at this .htaccess approach which looks if there is a maintenance.html at document_root and if so it will redirect all requests to it and serve the correct status code
RewriteEngine On
# Maintenance mode if /maintenance.html is present
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
so means if you want to activate maintenance mode just upload the file to you webdir
Upvotes: 3
Reputation: 763
There's a very good symfony bundle. Check this out
You just install it in your project and then you can put your site in maintenance mode with just a command line.
You can set up many configurations like the duration of this state, custom error page and so on.
Upvotes: 4