dcabrejas/magento-rate-limit

使用Token Bucket算法和Magento适配器的速率限制库

1.0.0 2017-07-04 15:23 UTC

This package is not auto-updated.

Last update: 2024-09-24 17:24:11 UTC


README

touhonoob/RateLimit库提供的Magento 2适配器

安装

composer require dcabrejas/magento-rate-limit

使用方法

//Inject the adapter via dependency injection
public function __construct(\Dcabrejas\RateLimit\Adapter\Magento $magentoAdapter)
{
  $this->magentoAdapter = $magentoAdapter;
}


$rateLimit = new \Touhonoob\RateLimit\RateLimit("myratelimit", 100, 3600, $this->magentoAdapter); // 100 Requests / Hour

$id = $_SERVER['REMOTE_ADDR']; // Use client IP as identity
if ($rateLimit->check($id) > 0) {
  echo "passed";
} else {
  echo "rate limit exceeded";
}