-
Add this project in your composer.json:
"require": { "zend-modules/maintenance": "dev-master" }
-
Now tell composer to download the maintenance mode component by running the command:
$ php composer.phar update
- Clone this project into your
./vendor/
directory.
Warning This installation type will only allow the component to be installed as a module.
There are two ways to set this component.
-
Enabling it in your
application.config.php
file.<?php return array( // ... 'service_manager' => array( 'factories' => array( 'MaintenanceConfig' => 'Maintenance\Service\MaintenanceConfigFactory', ), 'invokables' => array( 'MaintenanceListener => 'Maintenance\Service\MaintenanceListener', ), ), 'listeners' => array( 'MaintenanceListener', ), );
-
Enabling it in your
application.config.php
file.<?php return array( 'modules' => array( // ... 'Maintenance', ), // ... );
The configuration must be made in your application.config.php
file. This is so as the maintenance module will take effect over all your application. The main entry will be maintenance_mode
.
-
Enabling it in your
application.config.php
file.<?php return array( // ... 'maintenance_mode' => array( 'enabled' => true, ), // ... );
The default value for enabled
is false
. Therefore, to disable you may comment out the line or set it to false
.
You may enable certain IP addresses to access yur site during maintenance mode. To do so you must define the whitelist of IP addresses.
-
Set the whitelist in your
application.config.php
file.<?php return array( // ... 'maintenance_mode' => array( 'enabled' => true, 'whitelist' => array( '127.0.0.1', ), ), // ... );
-
Set the template path in your
application.config.php
file.<?php return array( // ... 'maintenance_mode' => array( 'enabled' => true, 'template' => dirname(__DIR__) . '/views/layout/maintenance.phtml', ), // ... );
The Retry-After
HTTP header may be sent for responses with a status code set to 503. If the config value is not set, set to a past date, or the status code is not 503; then the header will not be set.
-
Set the full date and time for the retry-after header in your
application.config.php
file.<?php return array( // ... 'retry_after' => '2015-12-07 00:00:00', // ... );
By default, the server will return a 503 (Service Unavailable) HTTP status code when in maintenance mode. If you wish to change the HTTP status code for any reason you may do so.
-
Set the desired HTTP status code in your
application.config.php
file.<?php return array( // ... 'maintenance_mode' => array( 'status_code' => 500, ), // ... );
Sometimes we may wish to set the maintenance mode options from another source such as a database backend. This can be done with no problem as the maintenance mode configuration is stored in the service manager. Simply make your changes on the bootstrap event. As an example:
```php
<?php
namespace Application;
use Zend\EventManager\EventInterface;
class Module
{
public function onBootstrap(EventInterface $e)
{
if (!$e instanceof MvcEvent) {
return;
}
$serviceManager = $e->getApplication()->getServiceManager();
$maintenanceConfig = $serviceManager->get('MaintenanceConfig');
$maintenanceConfig->setEnabled(true);
}
}
```