Hyperf ?????? ???? ?? ??? ???? ??
Oct 20, 2023 pm 01:58 PMHyperf ?????? ???? ?? ??? ???? ??
??:
?? ??? ????????? ?? ????? ???? ???? ???? ??? ?? ?????. ?? ??? ???? ?? ?? ? ?????. ? ????? Hyperf ?????? ???? ?? ??? ???? ?? ?? ??? ???? ??? ?????.
1. ?? ?? ????? ?? ?? ??? ?? ?? ???? ?? ???? ???? ?? ???? ?? ?? ?? ?? ???? ?? ?? ?? ??? ???? ?? ?????. ???? ?? ?? ??? ?? ? ?? ??? ??? ???? ??? ? ????. Hyperf ?????? ?? ?? ???? ? ?? ?? ????? ???? ??? ?? ?? ?? ??? ?????.
- Hyperf ????? ??
- ?? Hyperf ?????? ???? ???. Composer? ?? ??? ? ????. ???? ?? ??? Hyperf ?? ??? ?????.
?? ?? ?? ???? ?? - Hyperf ???????? ????? ?? ?? ?? ??? ??? ? ????. ?? ??? ?? ?? ?? ?? ????? ??? ? ????:
namespace AppMiddleware;use HyperfDiAnnotationInject;
use HyperfHttpServerContractRequestInterface;
use HyperfHttpServerContractResponseInterface; mitAnnotationRateLimit;
use HyperfRateLimitAspectRateLimitAspect;
?
class RequestLimitMiddleware
{
/** * @Inject * @var RequestInterface */ protected $request; /** * @Inject * @var ResponseInterface */ protected $response; public function process($request, $handler): ResponseInterface { // 獲取請求的IP地址 $ip = $this->request->getServerParams()['remote_addr']; // 檢查IP是否在限流規(guī)則中 if (! $this->isRequestAllowed($ip)) { $this->response->json(['message' => '請求過于頻繁,請稍后再試'], 429); } return $handler->handle($request); } /** * 檢查請求是否允許 */ protected function isRequestAllowed(string $ip): bool { // 這里可以根據具體的限流算法進行實現(xiàn),例如使用令牌桶算法或漏桶算法 // 返回true表示允許請求,返回false表示請求被限制 }
}? ????? @RateLimit ??? ?? ?????? ?? ??? ???? ?? ???? ?? ?? ?? ??? ?????. ??? ??? ????? ??? ???? ?????? ??? ?????.
- ?? ?? ??? ?? ???? ??
- Hyperf ?????? ?? ?? config/autoload/middlewares.php?? ?? ?? ??? ?? ????? ??? ? ????. ?? ?? ?? ??? ?? ????? ?????.
[
'http' => [// ... AppMiddlewareRequestLimitMiddleware::class => [ 'priority' => 99, 'rate' => 100, // 每秒最多100個請求 'capacity' => 100, // 令牌桶的容量為100 ], // ...
],]? ????? ?? ???? ?? ?? ?? ??? ??? ? ????. ?? ?? . ?? ?? ????? ?? ??? ?? ??? ? ????.
Hyperf ????? ??Hyperf ?????? ???? ????? ??? ?? ?? ???? ??? ???? ?????.
? ??? Hyperf ?????? ???? ?? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

?? ?? ??? ?? Hyperf ?????? ???? ?? ??: ?? ??? ????????? ?? ????? ???? ???? ???? ??? ?? ?????. ?? ??? ???? ?? ?? ? ?????. ? ????? Hyperf ?????? ???? ?? ??? ???? ?? ?? ??? ???? ??? ?????. 1. ?? ?? ???? ?????? ?? ?? ??? ?? ?? ???? ?? ???? ???? ?? ???? ?? ?? ?? ?? ???? ?? ?? ?? ??? ???? ?? ?????. ???? ?? ?? ??? ?? ? ?? ??? ??? ???? ??? ? ????. ??

2004? ?? ?? PHP? ???? ?? ?? ?? ?? ?? ? ??? ?????. ???? ??? ??? ???? ?? ???? ?? PHP? ??? ?? ??? ???? ????. ? ? ??????? ????? ??? ????? ???? ?? ?? ?? ???? ?????. ? ????? ????? ???? PHPHyperf ??????? ??? ??? ?????. 1. ??????? ????? ?????? ??????? ????? ????? ??? ??? ??? ?? ?? ??? ???? ??? ??? ???????. ??????? ????? ??? ???? ?????? ????? ????

Hyperf? ??? ???? ?? ??? ??? PHP ????????. Hyperf ?????? ???? ???? ???? ?? ??? ??? ??? ?? ???? ???. ? ????? ?? ??? ?? Hyperf ?????? ???? ??? ???? ?? ?? ??? ?????. 1. ?? ??? ?? Hyperf ?????? ???? ??? ? ?? ??? ????? config ????? ??? .env ??? ??? ? ????.

?? ????? ?? Hyperf ?????? ???? ?? ??: ?? ????? Hyperf ?????? ???? ? ??????? ??? ? ???? ?? ?????. ? ????? ?? ?? ??? ???? ?? ????? Hyperf ?????? ???? ??? ?????. 1. ?? ???? ?? Hyperf ?????? ???? Hyperf ??????? ????? ????? ?????. 2. ?? ???? ???? ?? ?? ?? ???? ??? ??? ????? ???? ???. ???? ?? ?????

??? ??? ?? Hyperf ?????? ???? ?? ??: ??? ???? ??? ???? ?? ?? ? ???? ??? ??? ?? ? ????? ????. Hyperf? Swoole ??? ??? ?????? ??? ??? ??? ??? ?? ??? ??? ?????. ? ????? ??? ??? ?? Hyperf ?????? ???? ??? ???? ?? ?? ??? ?????. 1. Hyperf ????? ??: ???? ?? ?? Hyperf ?????? ?????? ?????. ??

??? ???? ?? Hyperf ?????? ???? ?? ??: ??? ???? ?? ? ???? ?? ??????. ???? ???? ???? ??? ???? ? ?? ??? ? ????. Hyperf? ??? ??? ?? ?? ??? ???? ??? PHP ????????. ? ????? ??? ???? ?? Hyperf ?????? ???? ??? ???? ??? ?? ??? ?????. 1. ??: ???? ?? Hyperf ?????? ???? ?? ? ?????? ???? ???. Composer? ?? ?? ??

Hyperf ?????? ???? Excel? ???? ???? ?? ??: ? ????? Hyperf ??????? Excel ??? ???? ? ???? ??? ???? ??? ???? ???? ?? ??? ?????. ???: Hyperf ?????, Excel ????, Excel ????, ?? ?? ???? ?? phpoffice/phpspreadsheet ?????? ????? ???? ??? ???? ???. ????? ?? ??? ???? ??? ? ????.

PHPHyperf? ??? ??? ??? ??? ?? ???? ??? ??????? ????????. ? ????? ??????? ???? ???? PHPHyperf? ??? ??????? ??? ?? ??? ?????. 1. ?? ?? ??????? ??? ?? PHPHyperf? ???? ?? ??? ???? ???. ?? PHP ?? ??? ???? ?? ??? 7.2 ???? ?????. ??, PHP ??? ???? ????? Composer? ?????. ???,
