Back to all funny docs

# Concurrent Chaos, or How to Make Your Computer Dance Simultaneously ๐Ÿ•บ๏ธ๐Ÿ’ƒ๏ธ

Warning: May cause actual learning AND laughter!

Concurrent Chaos, or How to Make Your Computer Dance Simultaneously ๐Ÿ•บ๏ธ๐Ÿ’ƒ๏ธ

A Brief Overview (A.K.A. The Spark Notes Version for the Lazy)

Ah, concurrency! Itโ€™s like asking your computer to juggle while doing a rain dance and solving a Rubikโ€™s cubeโ€ฆ all at once. But fear not, dear Laravel user! Weโ€™ve got you covered with some magical PHP code that makes this modern-day magic trick possible.

Running Concurrent Tasks (A.K.A. When You Need a Multitasking Masterclass)

Now, when youโ€™ve got tasks piling up faster than a buffet during happy hour, itโ€™s time to get your computer in on the action. With Laravel, you can unleash its secret ninja skills and have it juggle multiple tasks simultaneously. Itโ€™s like having an assistant with superpowers! ๐Ÿฆธ๏ธโ€โ™‚๏ธ

Deferring Concurrent Tasks (A.K.A. When You Need to Outsource Your Jobs)

Sometimes, youโ€™ve got tasks that can wait their turn, and itโ€™s best to let them rest in peace until theyโ€™re needed. Enter deferred concurrency! With this Laravel feature, you can schedule those tasks to run at a later time without holding up the main event. Itโ€™s like hiring a task manager for your computer! ๐Ÿ•ฐ๏ธ๐Ÿ“…

So there you have it, concurrency in all its glory! Embrace the future and let your Laravel application become the ultimate multitasker, handling tasks faster than you can say โ€œWhereโ€™d my sandwich go?โ€ ๐Ÿฅช

Ahoy there, coding sea dogs! Sail with me on a journey through the treacherous waters of Laravelโ€™s Concurrency facade โ€“ your trusty compass for conquering those sluggish tasks that have been dragging anchor on your applicationโ€™s performance!

Imagine youโ€™ve got a pirate crew, each member tasked with a distinct chore, yet not one pirate depends on another to finish their work. To maximize booty gathering, it makes sense for them to hoist sails concurrently, right? Well, thatโ€™s exactly what Laravelโ€™s Concurrency facade does for your tasks!

Now, let me swab the decks and explain how it works!

How It Works (Arrrr!)

Picture this: youโ€™ve got a rowdy crew of closures that need to be executed, but donโ€™t want to make โ€˜em wait in line like common landlubbers. No sirree! By invoking the Laravel Concurrency facade, these closures will set sail on their own, each one racing against time and sea monsters (or perhaps just PHP processes) to complete their task.

To get started with this swashbuckling feature, simply call the concurrent() method from your trusty ship โ€“ I mean controller or job โ€“ and pass it a list of closures. The Concurrency facade will take care of the rest, setting off these closures on separate voyages to ensure maximum performance gains (and less waiting for ye scurvy landlubbers).

So, hoist those sails high, my hearties! Itโ€™s time to conquer those sluggish tasks and let Laravelโ€™s Concurrency facade lead the charge! Yo ho ho and a bottle of rum!

In a nutshell, Laravelโ€™s secret sauce for handling multiple tasks at once involves a magical dance between your closures, a stealthy Artisan CLI command, and some serious PHP voodoo. Hereโ€™s the lowdown:

  1. Your lovely closure gets wrapped up tight like a Christmas present and is then sent off to hang out with our Artisan CLI pal.
  2. Our Artisan friend unwraps your closure and throws an impromptu party for it in its very own PHP process, ensuring everyone (tasks) has their own space to boogie.
  3. After the bash, the result of the party (your taskโ€™s outcome) gets wrapped up again and sent back to the original process, aka the host with the most.

The Concurrency facade is our swanky bartender, mixing up three martinis (drivers): process (the default), fork, and sync.

  • The fork driver is our fast-talking, suave charm whoโ€™s great at impressing guests when PHPโ€™s in its CLI best, but unfortunately canโ€™t keep the conversation going during web requests. So, before you introduce them to your guests, make sure to invite them over when PHPโ€™s dressed for the occasion by installing the spatie/fork package:
composer require spatie/fork
  • The sync driver is our reliable old pal who always shows up when you need them, even if it means sticking around during testing and preventing any concurrency at all. Theyโ€™re the one you invite to the party when you want a drama-free evening with your closures neatly lined up and executed in order within the parent process.

Cheers to a more entertaining Laravel journey! ๐ŸŽ‰๐Ÿพ

Unleashing the Multitasking Champs of Laravel! ๐Ÿš€

Ready to witness some PHP superheroes juggling tasks like circus acrobats? Behold, the power of concurrent task execution! ๐Ÿคนโ€โ™‚๏ธ

To kickstart this symphony of simultaneous operations, summon the almighty Concurrency facade and its trusty run method. The run method is a bit like calling up your friends for a group movie night, only it takes an array of closures instead of popcorn flavors:

use Illuminate\Support\Facades\Concurrency;
use Illuminate\Support\Facades\DB;

[$userCount, $orderCount] = Concurrency::run([
    fn () => DB::table('users')->count(), // Counting our users like it's nobody's business
    fn () => DB::table('orders')->count(), // Orders on the line, we've got you covered!
]);

Now, if you prefer a specific superhero to join the party (ahem, driver), simply use the driver method:

$results = Concurrency::driver('fork')->run(...); // Fork over those tasks, let's get this show on the road!

And if you want to swap out your main concurrency hero for a new one, you can publish the concurrency configuration file using the config:publish Artisan command and then adjust the default option within the file:

php artisan config:publish concurrency // Let's give our configuration file a makeover!

Now, go forth and orchestrate your own superhero multitasking session in Laravel, and never let those tasks pile up again! ๐ŸŽ‰๐Ÿ’ฅ๐Ÿš€

Ahoy there, Laravel Pirate! Ever find yourself in a pickle, needing to execute a gang of closures like a swarm of seagulls on a shipwreck, but without caring for the loot they bring back? Fear not, me hearty! For we got just the thing to make ye day bright as a sunny day at sea - the mighty defer method!

When ye summon this powerful spell, itโ€™ll keep those closures from running amok right away. Instead, itโ€™ll hold off till after yerHTTP response has been fired off to old Long John Silver and his kin, like a well-timed cannonball that wonโ€™t disturb your guests at dinner!

Here be an example of how ye can use it:

use Artin's Treasure\Metrics;
use Illuminate\Support\Facades\Concurrency;

Concurrency::defer([
    function () { Metrics::report('shiver me timbers, users!'); },
    function () { Metrics::report('arr matey, orders!'); }
]);

Now go forth and conquer the high seas of async tasks with ease, matey!

Other Funny Docs

**Welcome to Laravel Land!** ๐ŸŒ„ # Collections ๐ŸŽ‰๐ŸŽฉ # 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! ๐Ÿฆธโ€โ™‚๏ธ๐Ÿš€ Rockstar Rate Limiting ๐ŸŽธ๐Ÿฅ๐ŸŽ‰ 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! ๐Ÿง™โ€โ™‚๏ธ๐Ÿ”ฎ