mcprohosting/flywheel 问题修复 & 功能扩展

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

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

mcprohosting/flywheel

Composer 安装命令:

composer require mcprohosting/flywheel

包简介

React to rates

README 文档

README

Flywheel is a small Laravel package for reacting differently under varying levels of load. It isn't an extremely precise mechanism - it's optimized for speed and designed to hold up under rigorous circumstances (that's where it's meant to be used, after all!). Its intention is allowing the application to, under high strain such as a denial of service attack, forgo expensive but not mission-critical functionality.

It does this by storing a single string to the cache for each "flywheel". This is quite small and consists of two concatenated values, which are used to do a kind of linear regression to determine the load of the application on the interval. It's designed to be fast, not highly accurate, and to add the minimal possible overhead to the system.

Usage

  1. Install the package with Laravel.
  2. Register its service provider, Mcprohosting\Flywheel\FlywheelServiceProvider
  3. You may wish to register its facade as an alias, "Flywheel" => "Mcprohosting\Flywheel\Flywheel"
  4. Profit?

Factory method: Flywheel::make(string $name, float $interval, callable|array $level)

Instantiate a new Flywheel. $name is a fairly arbitrary string, just used to identify the given wheel with the cache. $interval should be the given interval, in seconds, that you want to "monitor" against. $level should be an array, with its keys being the number of calls it takes to reach that "level" and values being callables that are called at each level. For example:

$wheel = Flywheel::make('loadStatus', 3, array(
    0  => function ($name) { echo "Load is A-Okay, $name!"; },
    10 => function ($name) { echo "We're getting some load, $name."; },
    50 => function ($name) { echo "We have so much load, $name!"; }
));

$wheel->spin('Connor');

Now, if this page gets between zero and ten visitors in a period of three seconds, it'll show the first message: "Load is A-Okay, Connor!" If it gets between ten and fifty, it will likewise show the second message. Any more than that, the third message will be shown. You may have noticed that any arguments that get passed to spin() will be passed on as arguments to whatever is called for the current level.

You can alternately declare levels dynamically. This may be preferable, as you're able create the Wheel when the application boots, but bind the logic on where and when it is necessary.

$wheel = Flywheel::make('loadStatus', 3);
$wheel->addLevel(0, function ($name) { echo "Load is A-Okay, $name!"; });
$wheel->addLevel(10, function ($name) { echo "We're getting some load, $name."; });
$wheel->addLevel(50, function ($name) { echo "We have so much load, $name!"; });

$wheel->spin('Connor');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2014-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固