定制 axvi/laravel-maintenance 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

axvi/laravel-maintenance

Composer 安装命令:

composer require axvi/laravel-maintenance

包简介

Advanced maintenance mode management for Laravel — IP whitelisting, named bypass tokens, scheduled windows, and more.

README 文档

README

Advanced maintenance mode management for Laravel 10, 11 and 12.

Latest Version on Packagist License

Features

  • IP address whitelisting with optional expiration
  • Multiple named bypass tokens (cookie for web, header for APIs, URL bypass)
  • Scheduled maintenance windows with auto-disable
  • Beautiful, customizable 503 page with countdown timer
  • Database-driven — works seamlessly across multiple servers
  • Built-in cache layer — avoids DB queries on every request
  • Exclude paths from maintenance (health checks, webhooks, etc.)
  • Configurable database connection and table names
  • Artisan commands for full CLI management
  • Events: MaintenanceModeEnabled, MaintenanceModeDisabled, MaintenanceBypassGranted
  • Automatically replaces Laravel's built-in maintenance middleware

Requirements

PHP 8.1 PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
Laravel 10 yes yes yes yes
Laravel 11 yes yes yes yes
Laravel 12 yes yes yes yes

Installation

composer require axvi/laravel-maintenance

Run migrations:

php artisan migrate

Migrations are loaded automatically. If you need to customize them:

php artisan vendor:publish --tag=maintenance-migrations

Optionally publish the config:

php artisan vendor:publish --tag=maintenance-config

Optionally publish the 503 view:

php artisan vendor:publish --tag=maintenance-views

Configuration

After publishing, the config file is located at config/maintenance.php:

return [
    // Database connection (null = default)
    'connection' => env('MAINTENANCE_DB_CONNECTION', null),

    // Customize table names
    'tables' => [
        'settings' => 'maintenance_settings',
        'ips'      => 'maintenance_ips',
        'tokens'   => 'maintenance_tokens',
    ],

    // Cache maintenance state to avoid DB queries on every request
    'cache' => [
        'enabled' => true,
        'store'   => null,  // null = default cache store
        'ttl'     => 60,    // seconds
    ],

    // URL patterns that should never be blocked by maintenance mode
    'except' => [
        // 'api/health',
        // 'webhook/*',
    ],

    // Bypass route settings
    'bypass_route' => [
        'enabled' => true,
        'prefix'  => 'maintenance',  // GET /maintenance/{token}
    ],

    // Middleware settings
    'middleware' => [
        'cookie_name'     => 'laravel_maintenance',
        'cookie_lifetime' => 43200, // minutes (12 hours)
        'header_name'     => 'X-Maintenance-Token',
    ],

    // Response settings
    'response' => [
        'status'      => 503,
        'retry_after' => 60,
        'refresh'     => null,
        'view'        => 'maintenance::503',
    ],
];

Usage

Enable maintenance mode

# Basic
php artisan maintenance:down

# With message, IP whitelist and secret token
php artisan maintenance:down \
  --message="We'll be back in 30 minutes" \
  --allow=192.168.1.1 \
  --secret=my-secret-token \
  --ends-at="2025-01-01 03:00:00"

Disable maintenance mode

php artisan maintenance:up

Check status

php artisan maintenance:status

Manage IPs

php artisan maintenance:ip add 192.168.1.50 --label="Dev machine"
php artisan maintenance:ip add 10.0.0.1 --expires-at="2025-06-01 00:00:00"
php artisan maintenance:ip remove 192.168.1.50
php artisan maintenance:ip list

Manage tokens

# Add with auto-generated UUID token
php artisan maintenance:token add dev-token

# Add with explicit token value
php artisan maintenance:token add dev-token abc123

# Add with expiration
php artisan maintenance:token add temp-token --expires-at="2025-06-01 00:00:00"

php artisan maintenance:token revoke dev-token
php artisan maintenance:token list

Bypass methods

URL bypass (web)

Visit https://yourapp.com/maintenance/{secret-token} — sets a bypass cookie valid for 12 hours.

The route prefix is configurable via bypass_route.prefix in the config. You can also disable URL bypass entirely by setting bypass_route.enabled to false.

Header bypass (API)

X-Maintenance-Token: my-secret-token

The header name is configurable via middleware.header_name in the config.

Exclude paths

Some URLs should always be accessible, even during maintenance. Add patterns to the except array:

'except' => [
    'api/health',
    'webhook/*',
    'telescope*',
],

Supports wildcards via Laravel's Request::is().

Caching

By default, the package caches the maintenance state and IP whitelist to avoid database queries on every HTTP request. The cache is automatically invalidated when you enable/disable maintenance or modify the IP whitelist.

To disable caching:

'cache' => [
    'enabled' => false,
],

To use a specific cache store (e.g. Redis):

'cache' => [
    'enabled' => true,
    'store'   => 'redis',
    'ttl'     => 30,
],

Programmatic usage

use Axvi\Maintenance\Facades\Maintenance;

// Check status
Maintenance::isDown();

// Enable / disable
Maintenance::enable([
    'message'     => 'Deploying v2.0',
    'retry_after' => 120,
    'ends_at'     => '2025-01-01 03:00:00',
]);
Maintenance::disable();

// Manage IPs
Maintenance::addIp('192.168.1.1', 'Office', now()->addHours(6));
Maintenance::removeIp('192.168.1.1');

// Manage tokens
Maintenance::addToken('deploy', 'my-secret', now()->addDay());
Maintenance::revokeToken('deploy');

// Full status array
$status = Maintenance::getStatus();

// Flush cache manually
Maintenance::flushCache();

Events

Event Properties
MaintenanceModeEnabled string $message, ?string $endsAt
MaintenanceModeDisabled
MaintenanceBypassGranted string $type (ip/cookie/header/url), string $value
use Axvi\Maintenance\Events\MaintenanceModeEnabled;

Event::listen(MaintenanceModeEnabled::class, function ($event) {
    // Notify the team via Slack, etc.
});

How it works

This package replaces Laravel's built-in PreventRequestsDuringMaintenance middleware with its own CheckMaintenanceMode middleware. The bypass check order is:

  1. Excluded paths — URLs matching except patterns are always allowed
  2. IP whitelist — if the request IP is in the maintenance_ips table (cached)
  3. Cookie — if the request has a valid bypass cookie
  4. Header — if the request has a valid token in the X-Maintenance-Token header
  5. 503 response — HTML page with countdown (or JSON for API requests)

All state is stored in the database, so maintenance mode works consistently across multiple application servers. Lookups are cached to minimize performance impact.

Testing

composer test

Or directly:

vendor/bin/phpunit

License

MIT — see LICENSE.md.

axvi/laravel-maintenance 适用场景与选型建议

axvi/laravel-maintenance 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「maintenance」 「laravel」 「503」 「maintenance-mode」 「maintenance-page」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 axvi/laravel-maintenance 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 axvi/laravel-maintenance 我们能提供哪些服务?
定制开发 / 二次开发

基于 axvi/laravel-maintenance 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-01