Back to all funny docs

Rockstar Rate Limiting ๐ŸŽธ๐Ÿฅ๐ŸŽ‰

Warning: May cause actual learning AND laughter!

Rockstar Rate Limiting ๐ŸŽธ๐Ÿฅ๐ŸŽ‰

Welcome to the groovy land of controlled chaos! Hereโ€™s your guide on how to keep the party going while still keeping a handle on things ๐Ÿค˜.

Cache Configuration: The Secret Sauce ๐Ÿ”๐Ÿฅ„

Before we dive into the dance floor, letโ€™s set up our secret sauceโ€”the cache configuration! Get your dancing shoes ready because itโ€™s gonna be a hoot. ๐Ÿ•บ๐Ÿ’ƒ

Basic Usage: The First Dance ๐Ÿ•บ๐Ÿฟ๏ธ๐Ÿ’ƒ๐Ÿฟ๏ธ

Time to hit the floor and learn the moves! Hereโ€™s a step-by-step guide on how to do it right. ๐Ÿ’ฅ

Manually Incrementing Attempts: Show โ€˜em you mean business ๐Ÿค๐Ÿฟ๏ธ๐Ÿ’ช๐Ÿฟ๏ธ

Feeling frisky? Want to prove your mettle? This is where you show off those impressive math skills and manually increment those attempts. We dare ya! ๐Ÿฅณ

Clearing Attempts: Time for a rewind โฎ๏ธ๐Ÿ’ƒ

Oh no, someone stepped on your foot? No worries, itโ€™s time to clear the dance floor and start anew! This section will teach you how. ๐Ÿคฏ๐Ÿคช

Hello, Web Wranglers! ๐Ÿค“

Welcome to Laravelโ€™s Rate Limiting Playground! ๐Ÿš€

Weโ€™ve cooked up a super-simple, laughably easy rate limiting abstraction thatโ€™ll make your life easier than a well-buttered bagel. Pair it with your appโ€™s cache (weโ€™re talking about the coffee-fueled caching, not the leftover pizza in the fridge), and youโ€™ve got an effortless solution to limit any action within a time window thatโ€™ll make you say โ€œTime flies when youโ€™re having fun!โ€ ๐Ÿ•ฐ๏ธ

[!NOTE] If rate limiting incoming HTTP requests is more your jam, weโ€™ve got the docs for that. Check out our rate limiter middleware documentation.

Now, letโ€™s set up the kitchen (errโ€ฆ cache configuration). ๐Ÿ› ๏ธ๐Ÿš€

Unleash the Power of Caching, Comrades! (or: How I Learned to Stop Worrying and Love the Cache)

Ahoy there, fearless coder! Prepare thyself for a dazzling dance with the mystical realm of Laravelโ€™s cache configuration. But fear not, this journey wonโ€™t be as dull as a night spent watching paint dry - we promise some laughs along the way!

First off, you may have noticed that our dear rate limiter usually depends on your trusty application cache (defined by the default key in your applicationโ€™s cache configuration file). However, if you fancy changing horses mid-stream, you can dictate which cache driver the rate limiter should hitch its wagon to by defining a limiter key within the same hallowed document:

'default' => env('CACHE_STORE', 'database'),

'limiter' => 'redis', // [tl! add]

Aw, shucks, we almost forgot to make this a barrel of laughs! So letโ€™s imagine for a moment that our rate limiter is a wayward cowboy, and the cache drivers are his trusty steeds. The default setting saddles him up with a trusty olโ€™ horse called โ€˜databaseโ€™. But now youโ€™ve got yourself a fancy new horse named โ€˜redisโ€™, and our cowboy just canโ€™t resist the allure of that shiny saddle!

And so, the rodeo begins anew! May your caching be swift and your code never run aground. Keep on codinโ€™, partners! ๐Ÿค ๐ŸŽ๐Ÿš€

Ahoy there, matey! Buckle up as we delve into the world of the Illuminate\Support\Facades\RateLimiter - a pirateโ€™s treasure chest full of rate limiting fun! This facade is your gateway to interact with our shipโ€™s mighty rate limiter.

The swashbuckling method it offers that weโ€™ll focus on today is the attempt โ€“ a versatile tool used to limit the number of times a particular action (or โ€œcallbackโ€ in proper speak) can be executed within a given time frame, measured in seconds.

The attempt method works like this: when it runs out of remaining attempts for a specific callback, it returns false. Otherwise, itโ€™ll return either the callbackโ€™s result or true. The first argument that the attempt method accepts is the โ€œkeyโ€ โ€“ a string representing the action being rate limited. For instance, to limit sending messages:

use Illuminate\Support\Facades\RateLimiter;

$pirateSpeak = 'arrr';
if ($executed = RateLimiter::attempt(
    'send-message:' . $user->id . $pirateSpeak, // Combine user ID and a "pirate greeting" for fun!
    5, // Allow 5 messages per minute
    function() {
        // Send message to the parrot... or rather, the user.
    }
)) {
    if (!$executed) {
        return 'Arrr matey, too many messages sent!';
    }
}

If you find yourself in need of adjusting the time when attempts reset (also known as โ€œdecay rateโ€), you can provide a fourth argument to the attempt method. Letโ€™s make our example allow five attempts every two minutes:

$pirateSpeak = 'arrgh';
$executed = RateLimiter::attempt(
    'send-message:' . $user->id . $pirateSpeak, // Update the pirate greeting for added flavor!
    5, // Allow 5 messages per two minutes
    function() {
        // Send message to the parrot... or rather, the user.
    },
    120 // Reset attempts every 120 seconds (2 minutes)
);

Now that youโ€™ve learned the basics of our rate limiterโ€™s attempt, you can set sail on your journey to becoming a true rate limiting maestro! Yo ho, yo ho, a pirateโ€™s life for me!

Alright, buckle up, code cowboys and cowgirls! Letโ€™s dive into the wild west of rate limiting in Laravel land.

Yeehaw-ally Manual Rate Wrangling

If you fancy some old-fashioned human interaction with our trusty rate limiter sheriff, youโ€™ve come to the right corral! With a twang in our voice and a smirk on our face, letโ€™s see how we can round up some methods:

use Illuminate\Support\Facades\RateLimiter;

If you think your message horse has been overworked (`tooManyAttempts` method), just give it a lasso check:

```bash
if (RateLimiter::tooManyAttempts('send-message:'.$user->id, $perMinute = 5)) {
    return 'Whoa there! This message horse has outrun its six-shootin' quota!';
}

Give your message horse a fresh carrot (`increment` method):

```bash
RateLimiter::increment('send-message:'.$user->id);

// Time to send that message, partner!

Fancy counting the remaining carrots for your message horse? Look no further than our trusty remaining method:

if (RateLimiter::remaining('send-message:'.$user->id, $perMinute = 5)) {
    RateLimiter::increment('send-message:'.$user->id);

    // Send that message, cowpoke!
}

Need to feed your message horse a big olโ€™ carrot bouquet? No problemo, pass the desired amount to our increment method:

RateLimiter::increment('send-message:'.$user->id, amount: 5);

Now, letโ€™s rope in some more knowledge on determining limiter availability: (Just kidding, weโ€™re all out of horse metaphors for now.)

To learn more about the available rate limiters and their settings, consult our trusty Rate Limiting documentation. Happy trailblazing! ๐Ÿค ๐ŸŽ

Alright, letโ€™s dive into the thrilling world of rate limiting in Laravel, where weโ€™re not just coding, but conducting a symphony of digital throttling!

When your key (we like to call them โ€œdigital drumsticksโ€) reaches its limit, the availableIn method steps up as our timekeeper, telling us how many seconds are left until the band can start playing again:

Use Illuminate\Support\Facades\RateLimiter;

If RateLimiter::drumStickBash('send-message:' . $user->id, $perMinute = 5) is more like a drum solo than a duet,
    $seconds = RateLimiter::countdownToJam('send-message:' . $user->id);

    Return 'Give us a beat in '.$seconds.' seconds. Your digital drumsticks will be ready to roll again!';
}

RateLimiter::hitTheDrums('send-message:' . $user->id);

// Send message...

Now, if youโ€™re wondering how to clear those attempts after the jam session, fear not! Hereโ€™s how:

If you need to clear all attempts for a specific key (because letโ€™s be honest, sometimes we all need a clean slate):

RateLimiter::clear('send-message:' . $user->id);

But wait! Thereโ€™s more! If you want to clear just the locked attempts (we donโ€™t want to throw away the good times, do we?), use this:

RateLimiter::forget('send-message:' . $user->id);

And there you have it! Now youโ€™re not only a Laravel maestro, but also a digital drum circle leader, ensuring your users never get drummed out of the fun. Rock on!

Unleashing the Beast

Oh, you fancy yourself a limerick maestro? Well, grab your lariat and letโ€™s gallop into the wild west of rate limiting!

In this frontier town, weโ€™ve got a tool called clear, Thatโ€™ll reset attempts for each key that you hold dear. No more bottlenecks, no more delays, Just like the cavalry, itโ€™ll chase those troubles away!

Use yer six-shooters, App's models and signs,
Import Message and Facade of RateLimiter's designs.

When a message is read with a twirl of the hat,
Mark it as read, and clear that key won't regret.

RateLimiter::clear('send-message:'.$message->user_id)
Will ensure all attempts, like tumbleweeds, will abide.

Just remember, pardner, this ainโ€™t just a fancy dance, Youโ€™re handling data, so keep your code well-anchored!

Other Funny Docs

**Welcome to Laravel Land!** ๐ŸŒ„ # Collections ๐ŸŽ‰๐ŸŽฉ # Concurrent Chaos, or How to Make Your Computer Dance Simultaneously ๐Ÿ•บ๏ธ๐Ÿ’ƒ๏ธ # Controllers: The Gladiators of the Digital Colosseum ๐Ÿ† # Database: The Magical Scroll of Infinite Data! ๐Ÿง™โ€โ™‚๏ธ๐Ÿ“– # Eloquent: The Great Serialize-Off! ๐Ÿฅณ๐ŸŽ‰ # Eloquent: The Swanky Buffet of Data! ๐ŸŽ‰๐Ÿฝ๏ธ # Eloquent's Amorous Affairs: A Love Letter to Data Relations! # Hashbash 101: Laravel's Secret Sauce for Security! ๐Ÿ”’๐ŸŽ‰ # Laravel's Heart Monitor ๐Ÿ’ผ๐Ÿ•บ๏ธ # Laravel's Magical Deployment Genie: Envoy! ๐Ÿงžโ€โ™‚๏ธ๐ŸŽฉ # Laughter Logs ๐Ÿ˜ƒ # Locksmith Services: Laravel's Top-Secret Spy Kit ๐Ÿ”‘๐Ÿ•ต๏ธโ€โ™‚๏ธ # The Database Dance: A Laravel Ballroom Guide ๐Ÿ’ƒ๐Ÿป๐ŸŽ‰ # The Grand Ol' Setup! ๐ŸŽถ๐Ÿฅ # The Great File Adventure! ๐Ÿ“š ๐Ÿš€ # The Great Laravel Password Adventure # The Magnificent Mongoose's Guide to Storing Data in the Land of BSON! ๐Ÿฆ๐Ÿ“œ ๐Ÿ””๐Ÿ“ฃ **Attention All Developers!** A Journey Through Laravel's File System Jungle! ๐ŸŒณ๐Ÿ” Ahoy there, coders and jesters alike! Brace yourself for a thrilling journey through the fantastical realm of Laravel Strings - the magic ingredient that makes your apps talk to you like a wise old sage (or a chatty parrot, if you prefer). Ahoy there, database enthusiasts! Let's embark on a fantastical journey into the heart of Laravel's mystifying seed land! Yes, you heard it right โ€“ we're talking about Database Seeding! Ahoy there, intrepid coder! Set sail for a grand adventure with Laravel's swashbuckling documentation! ๐Ÿดโ€โ˜ ๏ธ Ahoy there, Laravel sailors! Buckle up for an exhilarating journey into the realm of Eloquent API Resources. This section is chock-full of goodies that'll make your RESTful dreams come true. Let's dive right in! ๐ŸŒŠ Ahoy there, matey! Buckle up for a whirlwind tour of Laravel's process management! This is where the magic happens, and by "magic," we mean command line sorcery. Ahoy, mateys! Sail the Laravel seas with us as we delve into the art of mockery - not the kind that makes people laugh (although that's always a plus), but the one that helps you write better tests. Ready to plunder treasures of knowledge? Let's set sail! Alright, let's dive into the hilarious world of Laravel Licensing! ๐ŸŽ ๐ŸŽช Alrighty, buckle up, coding cowboy (or cowgirl)! Let's dive into the wild west of Laravel deployment where we'll tame servers, tweak configurations, and optimize for speedier draw times. But first, a quick warning: this here is more than just roping cattle, so if you ain't familiar with server requirements, Nginx, FrankenPHP, or directory permissions, best hitch a ride on the documentation horse. Anchors Aweigh! Welcome to Laravel Sail! ๐Ÿšข๐Ÿš€ Console Chortles: The Laugh-and-Learn Guide ๐ŸŽค๏ธ Contracts: The Sworn Code of Laravel Land! ๐Ÿค๐Ÿ“œ Database: The Gateway to Data Nirvana ๐Ÿš€๐ŸŒŸ Database: The Quarry Master Database: Time Machine for Your Data Eloquent: The Magic of Mutators & Casting! ๐ŸŽฉโœจ Eloquent: The Magical Factory of Your Database Dreams! ๐Ÿงšโ€โ™‚๏ธ๐Ÿ› ๏ธ Eloquent: The Posh Puppy of PHP Database Frameworks! ๐Ÿถ Fancy Pants Shortcuts ๐Ÿคต๐Ÿ‘— Frontend Fun Times! ๐ŸŽ‰๐ŸŽˆ HTTP Hooligans: A Survival Guide for Web Shenanigans in Laravel Land! ๐Ÿค“ Laravel Cashier (Paddle): The Silicon Valley of Subscription Billing ๐Ÿš€โœจ Laravel Cashier: Your Buddy for Stripe Shenanigans! ๐Ÿ’ฐ๐Ÿ’ณ Laravel Dusk: The Web Browser Robot for Your Laravel App! ๐Ÿค– Laravel Flagship ๐Ÿณ๏ธโ€๐ŸŒˆ Laravel Forti-Fantastic! ๐ŸŽ‰๐Ÿฐ Laravel Mix: The Magical Elixir of Your Web Application's Happiness ๐Ÿฐ Laravel Octane: The Supercharged PHP Superhero! โšก๏ธ๐Ÿš€ Laravel Passport: The Magic Key to Your API Kingdom ๐Ÿ”‘โœจ Laravel Pint: Your Chill Buddy for Code Quality! ๐Ÿป Laravel Sanctum: Your Secret Weapon for API Security! ๐Ÿš€๐Ÿ›ก๏ธ Laravel Scout: The Sherlock of Databases! ๐Ÿ•ต๏ธโ€โ™‚๏ธ Laravel's AI Sidekick ๐Ÿš€๐Ÿค– Laravel's AI Time Machine ๐Ÿ•ฐ๏ธ๐Ÿš€ Laravel's Bag O' Tricks! Laravel's Dance Floor: A Symphony of Code! ๐ŸŽถ๐Ÿฅ Laravel's Magical Command-Line Puppeteer (MCP) โœจ๐ŸŽฉ Laravel's Magical Domain Whisperer: Valet! ๐Ÿง™โ€โ™‚๏ธ๐Ÿ”ฎ Laravel's Magical Homestead for Developers, Wizards, and Aliens! ๐Ÿก๐Ÿš€ Laravel's Magical, Shiny Socialite! ๐ŸŒˆโœจ Laravel's Shining Star: Horizon! ๐Ÿš€โœจ Laravel's Stargazing Gadget: Telescope! ๐Ÿ”ญ๐Ÿš€ Laravel's Swanky Navigation Guide! ๐Ÿ•บ๏ธ Laugh, Log, Love! ๐Ÿค– logging in Laravel ๐ŸŽ‰ Laugh, Test, Conquer: Your Laravel Guide to Fun-tastic Testing! ๐Ÿฅณ๐ŸŽ‰ Laughable Laravel HTTP Hilarity! ๐ŸŽญ๐Ÿ’ฌ Laughing at the Glitches: Laravel's Error Handling Guide! ๐Ÿ˜œ Laughter and Coding: A Journey to Laravel 13.0! (From the Stables of 12.x) Let's Chat Like Never Before with Laravel Broadcasting! ๐Ÿ—ฃ๏ธ๐ŸŽ™๏ธ Lingo-Magic: Make Your Laravel App Speak Every Language Under the Sun! ๐ŸŒ๐ŸŽ™๏ธ Middleware Mayhem! ๐Ÿ•น๏ธ๐Ÿฆธโ€โ™‚๏ธ Package Shenanigans! ๐ŸŽ‰๐Ÿฅณ Redis: The Swift, Silicon Superhero of Data Storage! ๐Ÿฆธโ€โ™‚๏ธ๐Ÿš€ Service Provider Shenanigans! ๐Ÿค˜ Temples of Data: Laravel's Views Temple (Don't worry, no incense required) The All-Knowing, Magic Bean of PHP Land! ๐Ÿช„๐Ÿš€ The Art of Email in Laravel Land! ๐Ÿ•ต๏ธโ€โ™‚๏ธ๐Ÿ’Œ The Art of Validation: A Laravel Masterclass! ๐ŸŽ‰๐ŸŽ“ The Artisan's Playground ๐Ÿง›โ€โ™‚๏ธ๐Ÿ”ฉ The Dance of Responses The Gatekeeper's Handbook (But Slightly More Entertaining) The Globetrotter's Guide to Laravel Sessions The Great Escape Act: Laravel's Magic Trick with Queues! The Great Interweb Explorer: Laravel's HTTP Client The Great Laravel Journey: A Comic Adventure! ๐ŸŽ‰๐Ÿš€ The Great Laravel Soiree: An Eventful Revelry! ๐ŸŽ‰๐ŸŽŠ The Incredible Journey of Email Verification! ๐Ÿš€๐Ÿ“ง The Incredible, Mysterious World of CSRF Protection! ๐Ÿฆนโ€โ™‚๏ธ๐Ÿ”’ The Joyful Symphony of Asset Bundling: Vite Edition! ๐ŸŽถ The Laravel Play-Doh Kit: Your Gateway to Fun and Fancy Web Development! ๐ŸŽจ๐ŸŒ The Magic Show of Laravel Lifecycle ๐ŸŽฉโœจ The Quest for Knowledge: A Laravel Adventure! ๐Ÿ“š๐Ÿš€ The Time Travelling Task Manager (TTTM) The Wild West of Web Navigation: Laravel's Routing! ๐Ÿค ๐ŸŽ  Time Travel, Laravel Style! ๐Ÿ”ฎโณ Title: **How to Contribute Like a Rockstar ๐ŸŽธ** Title: **Welcome to Laravel's Magical Terminal Tour!** ๐ŸŽช๐ŸŽง Unleash the Power of Cache! (Or, How to Speed Up Your App Without Breaking a Sweat) Unlocking the Kingdom! (aka, Authentication in Laravel) URL Navigation: The Cosmic Wayfarer's Guide to Cyberspace! ๐Ÿ›ธ๐Ÿš€ Welcome to Laravel Boost, the supercharger for your PHP applications! ๐Ÿš€๐Ÿ’จ Welcome to Laravel Land! ๐ŸŒด๐ŸŽ‰ Wickedly Wonderful Blade Templates! ๐Ÿง™โ€โ™‚๏ธ๐Ÿ”ฎ