PHPackages                             juliangut/zf-maintenance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. juliangut/zf-maintenance

ActiveLibrary

juliangut/zf-maintenance
========================

Zend Framework maintenance module

2.0(11y ago)53.0k4[2 issues](https://github.com/juliangut/zf-maintenance/issues)[1 PRs](https://github.com/juliangut/zf-maintenance/pulls)BSD-3-ClausePHPPHP &gt;=5.3.3

Since Oct 21Pushed 4y ago2 watchersCompare

[ Source](https://github.com/juliangut/zf-maintenance)[ Packagist](https://packagist.org/packages/juliangut/zf-maintenance)[ Docs](https://github.com/juliangut/zf-maintenance)[ RSS](/packages/juliangut-zf-maintenance/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (5)Used By (0)

[![Latest Version](https://camo.githubusercontent.com/596bfffbe0d216633d7796442cca197fdab3eb4e4b9b10f65f0098a54038c782/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/zf-maintenance)[![License](https://camo.githubusercontent.com/95128325574f0788e8cace8c63db99d552be01457e6f778e217ee3cd2c5ea103/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://github.com/juliangut/zf-maintenance/blob/master/LICENSE)

[![Build status](https://camo.githubusercontent.com/a8009863aa0eb195b9f84409a242eabd92a06f76808f911a05856aaf784f632f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/juliangut/zf-maintenance)[![Code Quality](https://camo.githubusercontent.com/07a7a2ac332412ce79ab3fd6177b85e22a78798f602f20b538fbf39cc30f8307/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/zf-maintenance)[![Code Coverage](https://camo.githubusercontent.com/c6965a9fecb2d329a9fae8240625aa347d58ec94a18b2779db0949c91a390d94/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/zf-maintenance)[![Total Downloads](https://camo.githubusercontent.com/a86f1963ed52959d13b280bc30e57e910ba98271d010a55d77d53058e02c214b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f7a662d6d61696e74656e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/zf-maintenance)

Juliangut Zend Framework Maintenance Module
===========================================

[](#juliangut-zend-framework-maintenance-module)

Maintenance module for Zend Framework 2.

Installation
------------

[](#installation)

1. Best way to install is using [Composer](https://getcomposer.org/):

```
php composer.phar require juliangut/zf-maintenance

```

or download it directly from github and place it in your application's `module/` directory.

2. Add `Jgut\Zf\Maintenance` module to the module section of your `config/application.config.php`
3. Copy `config\zf-maintenance.global.php.dist` to your `config` directory and rename it `zf-maintenance.global.php`
4. Install zend-developer-tools (optional)

```
php composer.phar require zendframework/zend-developer-tools

```

Configuration
-------------

[](#configuration)

Configuration example can be found in `config\zf-maintenance.global.php.dist`

```
use DateTime;

return array(
    'zf-maintenance' => array(
        // Strategy service to be used on maintenance
        'strategy' => 'ZfMaintenanceStrategy',

        // Template for the maintenance strategy
        'template' => 'zf-maintenance/maintenance',

        // Maintenance blocks access to application
        'block' => true,

        /*
         * Maintenance providers
         * Different means to activate maintenance mode
         */
        'providers' => array(
            'ZfMaintenanceConfigProvider' => array(
                'active' => false,
            ),
            'ZfMaintenanceConfigScheduledProvider' => array(
                'start'   => '2020-01-01 00:00:00',
                'end'     => new DateTime('2020-01-02 05:00:00'),
                'message' => 'Undergoing scheduled maintenance tasks',
            ),
            'ZfMaintenanceEnvironmentProvider' => array(
                'variable' => 'zf-maintenance',
                'value'    => 'On',
            ),
            'ZfMaintenanceFileProvider' => array(
                'file'    => __DIR__ . '/maintenance',
                'message' => 'We are currently running maintenance proccesses',
            ),
            'ZfMaintenanceCrontabProvider' => array(
                'expression' => '0 0 1 * *', // @monthly
                'interval'   => 'PT1H', // 1 hour
                'message'    => 'We are currently running maintenance proccesses',
            ),
        ),

        /*
         * Exceptions to maintenance mode
         * Provides a way to bypass maintenance mode by fulfilling at least one of the conditions
         */
        'exclusions' => array(
            'ZfMaintenanceIpExclusion' => array(
                '127.0.0.1',    // Localhost
                '192.168.1.10', // Private network
            ),
            'ZfMaintenanceRouteExclusion' => array(
                'home',
                'admin',
            ),
        ),
    ),
);
```

### Strategy

[](#strategy)

Custom strategy to handle maintenance mode.

To create your own just extend `Jgut\Zf\Maintenance\View\MaintenanceStrategy`

### Template

[](#template)

Template file for maintenance strategy

### Block

[](#block)

By default maintenance mode prevents application from continuing execution by throwing `Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR` handled by `Jgut\Zf\Maintenance\View\MaintenanceStrategy`

If you don't want maintenance mode to stop execution and show maintenance page then set block to false.

This can be used in case you are performing maintenance tasks that don't need the application to be shut down, like ddbb backup, ...

In this case it is usefull to use `maintenanceMessage` view helper to show maintenance information

### Providers

[](#providers)

Maintenance mode providers serve different means to activate maintenance mode

Providers are checked in the order they appear in providers array, when one provider is active the rest of providers are not checked

#### Common attributes

[](#common-attributes)

All maintenance providers have a `message` attribute used in maintenance strategy page

```
$provider = new ConfigProvider();
$provider->setMessage('custom maintenance mode message');
```

#### ConfigProvider

[](#configprovider)

Manual provider, set maintenance mode just by setting `active` attribute

```
use Jgut\Zf\Maintenance\Provider\ConfigProvider;

$provider = new ConfigProvider();
$provider->setActive(true);
```

#### EnvironmentProvider

[](#environmentprovider)

Environment variable check provider, checks an environment variable to set maintenance mode

```
use Jgut\Zf\Maintenance\Provider\EnvironmentProvider;

putenv('zf-maintenance=On');

$provider = new EnvironmentProvider();
$provider->setVar('zf-maintenance');
$provider->setValue('On');
```

#### FileProvider

[](#fileprovider)

File provider, verifies the existance of a file to set maintenance mode

```
use Jgut\Zf\Maintenance\Provider\FileProvider;

$provider = new FileProvider();
$provider->setFile(__DIR__ . '/maintenance_file');
```

#### Scheduled Providers

[](#scheduled-providers)

Any provider implementing `Jgut\Zf\Maintenance\Provider\ScheduledProviderInterface` will be used to determine future maintenance situations and used on `scheduledMaintenance` view helper as well as in zend-developer-tools

#### ConfigScheduledProvider

[](#configscheduledprovider)

Manually scheduled maintenance time frame

Maintenance mode will be set on during the time span provided by `start` and `end` attributes (DateTime valid string or object).

If only `start` provided maintenance mode won't stop once started. If only `end` provided maintenance mode will be on from this moment and until end time

```
use Jgut\Zf\Maintenance\Provider\ConfigScheduledProvider;
use DateTime;

$provider = new ConfigScheduledProvider();
$provider->setStart('2020-01-01 00:00:00');
$provider->setEnd(new DateTime('2020-01-01 05:00:00')),
```

#### CrontabProvider

[](#crontabprovider)

Scheduled maintenance based on [CRON expression syntax](https://en.wikipedia.org/wiki/Cron#CRON_expression)

```
 *    *    *    *    *    *
 |    |    |    |    |    |
 |    |    |    |    |    +--- Year [optional]
 |    |    |    |    +-------- Day of week (0-7) (Sunday=0|7)
 |    |    |    +------------- Month (1-12)
 |    |    +------------------ Day of month (1-31)
 |    +----------------------- Hour (0-23)
 +---------------------------- Minute (0-59)

```

Maintenance mode will be set on during the time span provided by CRON expression and `interval` attribute (valid DateInterval specification string).

```
use Jgut\Zf\Maintenance\Provider\CrontabProvider;

$provider = new CrontabProvider();
$provider->setExpression('@monthly'); // 0 0 1 * *
$provider->setInterval('PT1H'), // 1 hour

// Maintenance will be ON the 1st of every month at 0:00 during 1 hour
```

*Uses [Michael Dowling (mtdowling) cron-expression](https://github.com/mtdowling/cron-expression/tree/master)*

### Exclusions

[](#exclusions)

Conditions to bypass maintenance mode

Exclusions are checked the same way as providers are, in the order they are located in exclusions array, when one exclusion is active (isExcluded) the rest of exclusions are not checked

#### IpExclusion

[](#ipexclusion)

Excludes IPs from maintenance mode

```
use Jgut\Zf\Maintenance\Exclusion\IpExclusion;
use Zend\Http\PhpEnvironment\RemoteAddress;

$excludedIps = array(
    '127.0.0.1',
    '192.168.1.10',
);

$exclusion = new IpExclusion($excludedIps, new RemoteAddress);
```

#### RuteExclusion

[](#ruteexclusion)

Excludes routes from maintenance mode

```
use Jgut\Zf\Maintenance\Exclusion\RouteExclusion;
use Zend\Mvc\Router\RouteMatch;

$excludedRoutes = array(
    'routeName',
    array(
        'controller' => 'controllerName',
    ),
    array(
        'controller' => 'controllerName',
        'action'     => 'actionName',
    ),
);

$exclusion = new RouteExclusion($excludedRoutes, new RouteMatch);
```

View helpers
------------

[](#view-helpers)

### MaintenanceMessage

[](#maintenancemessage)

`maintenanceMessage` will return the message of current active maintenance provider or empty string if not in maintenance mode

Allows you to show maintenance message when maintenance is in non blocking state or for those users for who exclusions apply

This helper would normally be used on a general template as application header or footer as an informative area. Mind that if in maintenance blocking mode all requests not bound by exclusions will be redirected to maintenance page

```
$maintenanceMessage = $this->maintenanceMessage();
if ($maintenanceMessage !== '') {
    sprintf('%s', $maintenanceMessage);
}
```

### ScheduledMaintenance

[](#scheduledmaintenance)

`scheduledMaintenance` will return an array with the next scheduled maintenance time period

```
$maintenance = $this->scheduledMaintenance();
// Start or end can be null if not provided

/*
array(
    'start' => \DateTime,
    'end'   => \DateTime,
);
*/
```

ZendDeveloperTools integration
------------------------------

[](#zenddevelopertools-integration)

A collector `jgut-zf-maintenance-collector` is present for [ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools) showing current maintenance status and future scheduled maintenance period times

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/juliangut/zf-maintenance/issues). Have a look at existing issues before

See file [CONTRIBUTING.md](https://github.com/juliangut/zf-maintenance/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

### Release under BSD-3-Clause License.

[](#release-under-bsd-3-clause-license)

See file [LICENSE](https://github.com/juliangut/zf-maintenance/blob/master/LICENSE) included with the source code for a copy of the license terms

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Total

4

Last Release

4040d ago

Major Versions

0.5 → 1.02015-03-15

1.1 → 2.02015-04-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (120 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

---

Tags

zf2maintenance

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/juliangut-zf-maintenance/health.svg)

```
[![Health](https://phpackages.com/badges/juliangut-zf-maintenance/health.svg)](https://phpackages.com/packages/juliangut-zf-maintenance)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
