Laravel's throttle middleware failure solution, laravelthrottle

Source: Internet
Author: User

Laravel's throttle middleware failure solution, laravelthrottle

This example describes how to solve Laravel's throttle middleware failure problem. We will share this with you for your reference. The details are as follows:

According to the official explanation, the Access frequency limit is very simple:

Route: get ('test', function () {return 'helle world';})-> middleware ('throttle ');

This is also true. make a judgment on the number of cache storage accesses.

Zizaco/entrust (a role-based permission management package) was used before, and CACHE_DRIVER = file in. env was changed to CACHE_DRIVER = array. So the problem arises. Laravel supports multiple cache drivers, such as File, Array, Db, and Redis. However, throttle seems to be effective only when a File driver is used.

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 to the following. Throttle middleware also works.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.