PHP code example of sunsgne / rate-limit
1. Go to this page and download the library: Download sunsgne/rate-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/ */
sunsgne / rate-limit example snippets
$moreRateLimit = Container::get(MoreRateLimitHandler::class);
$capacity = 60;
$seconds = 60;
$customerHandle = [
'class' => \support\Response::class,
'constructor' => [
429,
array(),
json_encode(['success' => false, 'msg' => '请求次数太频繁'], 256),
],
];
if (false === $moreRateLimit->handle(intval($capacity), intval($seconds))) {
$newClass = $customerHandle['class'];
return new $newClass(... \array_values($customerHandle['constructor']));
}
return $handler($request);
$moreRateLimit = new \sunsgne\middleware\MoreRateLimit();
$capacity = 60;
$seconds = 60;
$customerHandle = [
'class' => \support\Response::class,
'constructor' => [
429,
array(),
json_encode(['success' => false, 'msg' => '请求次数太频繁'], 256),
],
];
if (false === $moreRateLimit->handle(intval($capacity), intval($seconds))) {
$newClass = $customerHandle['class'];
return new $newClass(... \array_values($customerHandle['constructor']));
}