PHP code example of tinywan / limit-traffic

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

    

tinywan / limit-traffic example snippets


return [
    // 全局中间件
    '' => [
        // ... 这里省略其它中间件
        Tinywan\LimitTraffic\Middleware\LimitTrafficMiddleware::class,
    ],
    // api应用中间件
    'api' => [
        Tinywan\LimitTraffic\Middleware\LimitTrafficMiddleware::class,
    ]
];

Route::any('/admin', [app\admin\controller\Index::class, 'index'])
->middleware([Tinywan\LimitTraffic\Middleware\LimitTrafficMiddleware::class]);

// 分组路由
Route::group('/blog', function () {
   Route::any('/create', function () {return response('create');});
})->middleware([Tinywan\LimitTraffic\Middleware\LimitTrafficMiddleware::class]);

Tinywan\LimitTraffic\RateLimiter::getRateLimit(); // 返回 [100, 600]

'body' => [
	'error_code' => 200,
	'message' => '请求太多请稍后重试'
]

vendor/bin/phpstan analyse src

vendor/bin/php-cs-fixer fix src