konsulting/laravel-maintenance-mode 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

konsulting/laravel-maintenance-mode

Composer 安装命令:

composer require konsulting/laravel-maintenance-mode

包简介

Programmatically manage maintenance mode in Laravel apps across multiple servers.

README 文档

README

Installation

Install via Composer:

composer require konsulting/laravel-maintenance-mode

Laravel 5.5+ will automatically discover the provider and facade.

Config

Publish the config file with:

php artisan vendor:publish --provider="Konsulting\Laravel\MaintenanceMode\MaintenanceModeProvider"

Middleware

The file driver is compatible with Laravel's existing maintenance mode middleware when using the default configuration values.

To use a different driver or a different file path, add the provided CheckForMaintenanceMode middleware to app/Http/Kernel.php.

class Kernel extends HttpKernel
{
    // ...
    protected $middleware = [
        \Konsulting\Laravel\MaintenanceMode\Middleware\CheckForMaintenanceMode::class,
        
        // You can remove the Illuminate CheckForMaintenanceMode middleware or leave it in
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        // ...
    ];
}

Basic usage

By default, the Laravel artisan up and artisan down commands are overridden and so may be used to activate and deactivate maintenance mode using the selected driver. If override_illuminate_commands is set to false in the config, the commands for maintenance mode are site:up and site:down.

The behaviour of maintenance mode is similar to Laravel's default artisan up/artisan down commands. When activated, the a payload containing information about the outage is stored using the chosen driver. This is picked up by the middleware, which throws Illuminate\Foundation\Http\Exceptions\MaintenanceModeException if maintenance mode is active. Laravel's exception handler deals with returning the correct response.

Drivers

By default there are three drivers included: file, cache and storage. The file driver is very similar to Laravel's built in maintenance mode in that it stores a payload file in the local filesystem. The cache and storage drivers are useful for when multiple webservers are serving the application, as they can be easily configured to store the payload at an external location such as a cache server.

See the configuration file for more information about the drivers.

Programmatic usage

Instantiation

The available drivers are: cache, file, and storage. More detail is contained in config/maintenance_mode.php.

$driver = new FileDriver(['file_path' => '/path/to/file']);
$maintenanceMode = new MaintenanceMode($driver);

Activating maintenance mode

Maintenance mode is activated with the MaintenanceMode::on() method.

When maintenance mode is activated, a payload object is created with the information given and stored by the chosen driver. This contains information about the site being taken down, including the at which maintenance mode was activated, the seconds between retry requests, any IP addresses that are allowed to access the site during maintenance mode, and a message associated with the downtime.

$message = 'Down for database upgrades.';
$allowedIps = ['192.168.10.10', '127.0.0.1'];
$secondsToRetry = 60;

$maintenanceMode->on($message, $allowedIps, $secondsToRetry);

$maintenanceMode->isOn(); // true

Retrieving down information

$retrievedPayload = $maintenanceMode->getDownInformation();
// new DownPayload([
//     'time'    => Carbon::now()->getTimestamp(),
//     'message' => 'Down for database upgrades.',
//     'retry'   => 60,
//     'allowed' => ['192.168.10.10', '127.0.0.1'],
// ]);

Deactivating maintenance mode

Maintenance mode is deactivated with the MaintenanceMode::off() method.

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-27