PHP code example of imj / frequency

1. Go to this page and download the library: Download imj/frequency 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/ */

    

imj / frequency example snippets


use Imj\Frequency;

$config = [
  'time_unit' => 5,
  'recycle'   => 120,
  'default'   => 0,
  'rules'	=> [
    10 => [
      10 => 1,  // 10分钟操作10次及以上返回1
      20 => 2,
      30 => 3,
      40 => 4,
    ],
    20 => [
      80 => 5
    ]
  ]
];

$redis = getRedis();
$freq = new Frequency($redis, $config);

$ip = getIp();
$ret= $freq->check($ip);
$min = 10;
$times = $freq->checkTimes($ip, $min);