PHP code example of jarir-ahmed / kill-switch

1. Go to this page and download the library: Download jarir-ahmed/kill-switch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jarir-ahmed / kill-switch example snippets


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);

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

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,
];
bash
# Enable
echo "1" > storage/kill-switch.txt

# Disable
echo "0" > storage/kill-switch.txt
bash
php artisan vendor:publish --provider="JarirAhmed\KillSwitch\KillSwitch\Laravel\KillSwitchServiceProvider" --tag=kill-switch-config