PHP Classes


Recommend this page to a friend!
  Classes of Insolita   Yii2 Maintenance   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Yii2 Maintenance
Implement a PHP maintenance mode in a Web site
Author: By
Last change:
Date: 1 year ago
Size: 2,178 bytes


Class file image Download

Custom mantenance component

* Component for maintenance mode behavior, focused on retrieve status from external configuration * Support ability for allow exclusive access in maintenance mode for specified ips * Support preliminar notice about soon maintenance works * Provide observable events when maintenance process or preliminar modes



The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist insolita/yii2-maintenance "~0.0.1"

or add

"insolita/yii2-maintenance": "~0.0.1"

to the require section of your composer.json file.


Once the extension is installed, add in config components section, and also bootstrap section :

              'enabledKey'=>'config key for maintennce indication',
              'preliminarKey'=>'config key for preliminar maintenance indication',
              'ipSkippedKey'=>'config key for comma-seperated ips with exclusive access',
              'catchRoute'=>['site/maintenance'], //- route catched all requests in maintenance mode
              //possible events use cases
              'on maintenance_process'=>function($event){
                  //$event->sender is maintenance component!
                     Yii::$app->getSession()->setFlash('warning','Site in maintenance mode!');
              'on maintenance_soon'=>function($event){
                  'After 5 minutes, the site will be serviced, please finish or save the undelivered messages');