This article mainly introduces the solution to Laravel's throttle middleware failure problem. It briefly analyzes the reasons for the throttle middleware failure problem and proposes a solution. It has certain reference value. Friends in need can refer to it
The example in this article describes how to solve the problem of Laravel's throttle middleware failure. Share it with everyone for your reference, the details are as follows:
According to the official explanation, it is very simple to implement access frequency limit:
Route::get('test', function(){ return 'helle world' ; })->middleware('throttle');
This is indeed the case, The cache stores the number of accesses and makes judgments.
I used zizaco/entrust (a role-based permission management package) before, in which CACHE_DRIVER=file in .env was changed to CACHE_DRIVER=array. So the problem arises. Laravel supports a variety of cache drivers, including File, Array, Db, Redis, etc., but throttle seems to be effective only when using File type drivers.
My modifications are as follows:
vendor/illuminate/cache/RateLimiter.php file
public function __construct(Cache $cache) { $this->cache = $cache; } public function __construct() { $this->cache = app('cache')->driver('file'); }
Change the above Just do the following. The throttle middleware also works.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to solve the problem of PHP mkdir() not having write permission
The above is the detailed content of How to solve the problem of Laravel's throttle middleware failure. For more information, please follow other related articles on the PHP Chinese website!