O'Reilly logo

Mastering Yii by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rate Limiting

When creating APIs, you may want to implement rate limiting within your API to prevent excessive requests being made to your API and exhausting server resources. This is extremely important if your API is dependent upon another API that has rate limits already in place. Rate limiting in Yii2 is implemented by yii\filters\RateLimiter and yii\filters\RateLimitInterface.

To get started with rate limiting, we first need to add yii\filters\Ratelimiter to our controller behaviors. The yii\filters\RateLimiter class is coupled to our user identity class. Consequently, rate limiting will only be applied to actions that are protected by authentication. Any action that is not protected by an authenticate filter will not have rate limiting applied ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required