PHPackages                             jarir-ahmed/kill-switch - 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. jarir-ahmed/kill-switch

ActiveLibrary

jarir-ahmed/kill-switch
=======================

A framework-agnostic PHP kill-switch package using PSR-15 middleware. Returns a maintenance page when enabled.

v1.0.0(yesterday)03↑2900%MITPHP ^8.0

Since Jul 19Compare

[ Source](https://github.com/jarir2020/jarir-ahmed-killswitch)[ Packagist](https://packagist.org/packages/jarir-ahmed/kill-switch)[ Docs](https://github.com/jarir2020/jarir-ahmed-killswitch)[ RSS](/packages/jarir-ahmed-kill-switch/feed)WikiDiscussions Synced today

READMEChangelogDependencies (6)Versions (2)Used By (0)

jarir-ahmed-killswitch
======================

[](#jarir-ahmed-killswitch)

Kill Switch
===========

[](#kill-switch)

A framework-agnostic PHP kill-switch package using PSR-15 middleware. When enabled, every request returns a 503 maintenance page with the message **"We are In Maintenance Mode"**.

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

[](#installation)

```
composer require jarir-ahmed/kill-switch
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- `psr/http-message`
- `psr/http-server-middleware`
- `psr/http-factory`

Usage
-----

[](#usage)

### Configuration

[](#configuration)

The kill switch state is checked in this priority order:

1. **Environment variable** — `KILL_SWITCH_ENABLED` (`true` / `false`)
2. **File** — configurable path, contents must match `file_enabled_value` (default: `1`)
3. **Database** — DSN + table + column, toggled externally

### PSR-15 Middleware (Any Framework)

[](#psr-15-middleware-any-framework)

```
use JarirAhmed\KillSwitch\KillSwitch\KillSwitchManager;
use JarirAhmed\KillSwitch\KillSwitch\KillSwitchMiddleware;
use JarirAhmed\KillSwitch\KillSwitch\MaintenanceResponder;
use Nyholm\Psr7\Factory\Psr17Factory;

$config = [
    'env_var' => 'KILL_SWITCH_ENABLED',
    'file_path' => __DIR__ . '/../storage/kill-switch.txt',
    'file_enabled_value' => '1',
    'db' => [
        'connection' => 'mysql:host=localhost;dbname=app',
        'table' => 'settings',
        'column' => 'enabled',
        'id' => 1,
    ],
    'view_path' => null,
    'message' => 'We are In Maintenance Mode',
    'retry_after' => 3600,
];

$manager = new KillSwitchManager($config);

$responseFactory = new Psr17Factory();
$responder = new MaintenanceResponder($config, $responseFactory);
$middleware = new KillSwitchMiddleware($manager, $responder);

// Add to your PSR-15 middleware stack
$stack->add($middleware);
```

### Toggle Methods

[](#toggle-methods)

#### Env Variable

[](#env-variable)

```
# Enable
export KILL_SWITCH_ENABLED=true

# Disable
export KILL_SWITCH_ENABLED=false
```

Or in `.env`:

```
KILL_SWITCH_ENABLED=true

```

#### File

[](#file)

```
# Enable
echo "1" > storage/kill-switch.txt

# Disable
echo "0" > storage/kill-switch.txt
```

#### Database

[](#database)

```
UPDATE settings SET enabled = 1 WHERE id = 1;
UPDATE settings SET enabled = 0 WHERE id = 1;
```

Laravel Integration
-------------------

[](#laravel-integration)

### Step 1: Publish Config (Optional)

[](#step-1-publish-config-optional)

```
php artisan vendor:publish --provider="JarirAhmed\KillSwitch\KillSwitch\Laravel\KillSwitchServiceProvider" --tag=kill-switch-config
```

### Step 2: Register Middleware

[](#step-2-register-middleware)

In `app/Http/Kernel.php`:

```
protected $middleware = [
    \JarirAhmed\KillSwitch\KillSwitch\Laravel\KillSwitchLaravelMiddleware::class,
];
```

### Step 3: Configure

[](#step-3-configure)

Edit `config/kill-switch.php`:

```
return [
    'env_var' => 'KILL_SWITCH_ENABLED',
    'file_path' => storage_path('kill-switch.txt'),
    'file_enabled_value' => '1',
    'db' => [
        'connection' => env('DB_CONNECTION'),
        'table' => 'settings',
        'column' => 'kill_switch_enabled',
        'id' => 1,
    ],
    'view_path' => resource_path('views/maintenance.html'),
    'message' => 'We are In Maintenance Mode',
    'retry_after' => 3600,
];
```

Custom Maintenance Page
-----------------------

[](#custom-maintenance-page)

Place your custom HTML at the configured `view_path`. The default template is at:

```
resources/views/maintenance.html

```

Testing
-------

[](#testing)

```
vendor/bin/phpunit
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20700f34ff813055154e843bbdbe04d33320c1e6a81bbb3301cad67cb8350fd3?d=identicon)[jarircse16](/maintainers/jarircse16)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jarir-ahmed-kill-switch/health.svg)

```
[![Health](https://phpackages.com/badges/jarir-ahmed-kill-switch/health.svg)](https://phpackages.com/packages/jarir-ahmed-kill-switch)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.1k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k16](/packages/tempest-framework)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M592](/packages/shopware-core)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M89](/packages/mollie-mollie-api-php)

PHPackages © 2026

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