php - Runtime configuration for Symfony application
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?
Answer
Solution:
There's a very good symfony bundle. Check this out
LexikMaintenanceBundle
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.
Answer
Solution:
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
so means if you want to activate maintenance mode just upload the file to you webdir