Discover how to keep your app lightning-fast by offloading heavy work behind the scenes!
Why Dispatching jobs in Laravel? - Purpose & Use Cases
Imagine you have a website where users upload photos, and you need to resize each photo before showing it. Doing this resizing right when the user uploads can make them wait a long time.
Handling tasks like resizing images or sending emails immediately slows down your app. If you do everything right away, users wait too long, and your server can get overwhelmed.
Dispatching jobs lets you send these tasks to a background queue. Your app quickly accepts the user's request, then processes heavy work quietly behind the scenes without making users wait.
$image = Image::make($file); $image->resize(300, 300); $image->save('path/to/save');
ResizeImageJob::dispatch($file);
This lets your app stay fast and responsive while handling many tasks smoothly in the background.
When someone signs up, you can dispatch a job to send a welcome email later, so the signup feels instant and smooth.
Manual heavy tasks slow down user experience.
Dispatching jobs moves work to the background.
Apps stay fast and handle many tasks easily.