NoChecksum
NoChecksum

Reputation: 1226

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:

Has anyone found an efficient way to achieve this kind of feature? Am I re-inventing the wheel?

Upvotes: 3

Views: 401

Answers (2)

john Smith
john Smith

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

Omar Alves
Omar Alves

Reputation: 763

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.

Upvotes: 4

Related Questions