PHP code example of fengdangxing / hyperf-current-limit

1. Go to this page and download the library: Download fengdangxing/hyperf-current-limit 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/ */

    

fengdangxing / hyperf-current-limit example snippets


#配置路径 config/annotations.php 没有改文件新建
return [
    'scan' => [
        'paths' => [
            BASE_PATH . '/app',
            BASE_PATH . '/vendor/fengdangxing',//增加该配置
        ],
        'ignore_annotations' => [
            'mixin',
            'Notes',
            'Author',
            'Data',
            'Date'
        ],
    ],
];

return [
    'fengdangxing' => [
        'currentLimit' => [
            'rateLimitMin' => 50,//限流时间间隔内下限次数
            'rateLimitMax' => 100,//限流时间间隔内上限次数
            'rateLimitPeriod' => 5,//限流时间间隔s
            'rateLimitPausePeriod' => 5,//限流暂停时间s
            'rateLimitForbidPeriod' => 2 * 3600,//封禁时间s
        ]
    ]
];



declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use Fengdangxing\CurrentLimit\Annotation\CL;

class IndexController extends AbstractController
{
    /**
     * @CL(uniqueName="token|member_token|user_id",currentable=true,limitable=true)
     */
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();
        $list = PublishBatchModel::getAllList();
        return [
            'method' => $method,
            'message' => "Hello {$user}.",
            $list
        ];
    }
}
#uniqueName 唯一值;头部信息