PHP
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Functions
-
Section 4: Object-Oriented PHP
-
Section 5: Working with Data
-
Section 6: Modern PHP (PHP 8)
-
Section 7: Working with Files and Networking
-
Section 8: Common PHP Frameworks Overview
-
Section 9: Tooling and Ecosystem
-
Section 10: Practical Projects
-
Section 11: Interview Practice
-
Section 12: More Standard Library
-
Section 13: Data Structures and Algorithms in PHP
-
Section 14: More Practice Exercises
-
Section 15: More Security and Best Practices
-
Section 16: More Testing and Tooling
-
Section 17: WordPress-Style CMS Concepts
-
Section 18: Advanced OOP Practice
-
Section 19: More Web Fundamentals
-
Section 20: Database Practice
-
Section 21: PHP Manual: Array Functions
-
Section 22: PHP Manual: Date and Calendar Functions
-
Section 23: PHP Manual: Filesystem and Directory Functions
-
Section 24: PHP Manual: Filter and Var Handling
-
Section 25: PHP Manual: Math Functions
-
Section 26: PHP Manual: JSON and XML
-
Section 27: PHP Manual: Network and Stream Functions
-
Section 28: PHP Manual: Error and Exception Handling
-
Section 29: PHP Manual: Output Control and Misc
-
Section 30: PHP Manual: FTP, Zip, and Mail
-
Section 31: Modern PHP Frameworks Deep Dive
-
Section 32: PHP Design Patterns
-
Section 33: More Practice Exercises
-
Section 34: PHP Performance and Deployment
-
Section 35: More Interview Practice
-
Section 36: More PHP Standard Library
-
Section 37: PHP Concurrency and Async
-
Section 38: More Web Development Practice
-
Section 39: PHP Testing Deep Dive
-
Section 40: Composer and Package Development
-
Section 41: PHP Security Deep Dive
-
Section 42: More Practical Projects
-
Section 43: Legacy PHP Maintenance
-
Section 44: More Algorithm Practice
-
Section 45: Final Practice and Review
-
Section 46: PHP for E-Commerce Patterns
-
Section 47: PHP API Design Deep Dive
-
Section 48: PHP Caching Strategies
-
Section 49: PHP Queue and Background Jobs
-
Section 50: PHP Multi-Tenancy Patterns
-
Section 51: PHP Real-Time Features
-
Section 52: PHP CMS and Content Modeling
-
Section 53: PHP Internationalization
-
Section 54: More Framework-Specific Practice
-
Section 55: PHP Legacy Code Refactoring
-
Section 56: More Practice Projects Round 2
-
Section 57: PHP Command-Line Applications
-
Section 58: PHP and Microservices
-
Section 59: More Interview and Review Round 2
208: Laravel Horizon for Queue Monitoring
Why bother with Horizon when I can just run the queue worker?
Look, if you're running a tiny project, php artisan queue:work is perfectly fine. But the moment you move to production with actual users, that command becomes a black box. You have no idea if your jobs are piling up, if a specific job is crashing your worker, or if your "high priority" queue is being choked by a thousand "low priority" tasks.
I've spent way too many hours digging through text logs trying to figure out why a customer didn't receive a welcome email. Horizon changes that by giving you a beautiful, real-time dashboard. It tells you exactly how many jobs are pending, how long they're taking, and which ones failed. It effectively turns your Redis queue into something you can actually see and manage without having to SSH into your server and run redis-cli commands like a caveman.
How do I actually manage different priorities for my jobs?
This is where Horizon really shines. In a standard Laravel setup, you'd have to manage multiple supervisor processes for different queues. With Horizon, you do it all in config/horizon.php. Let's say you have a "notifications" queue (fast, high priority) and a "video-processing" queue (slow, resource-heavy).
You don't want your video uploads to stop your password reset emails from going out. You can set up a "balanced" strategy that automatically shifts worker resources where they're needed most. Here is how a typical configuration looks:
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['notifications', 'default', 'video-processing'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
],
By setting 'balance' => 'auto', Horizon monitors the workload. If the video-processing queue suddenly gets 10,000 jobs, Horizon will automatically allocate more of those 10 processes to that queue, then shift them back to notifications once the spike is over. It's a lifesaver for maintaining a snappy user experience.
What happens when a job fails and how do I handle it in Horizon?
We've all been there: a third-party API goes down, and suddenly 500 of your jobs fail. In a raw queue setup, you're stuck running php artisan queue:retry all and hoping for the best, or manually deleting bad jobs from a database table.
In Horizon, you get a "Failed Jobs" tab. You can see the exact exception that caused the failure and the payload that was sent with the job. If you realize the failure was caused by a bug you just patched in your code, you can select the failed jobs and click "Retry" right from the browser. I generally recommend keeping your tries count low in the config—maybe 3—so you aren't wasting CPU cycles on a job that's fundamentally broken. Once it hits that limit, Horizon parks it in the failed list for you to inspect manually.
📋 Practical Task
Configuring an Auto-Balancing Worker for an Order Fulfillment System
You are managing an e-commerce site. You have three queues: orders (critical), emails (standard), and reports (low priority/heavy). Currently, the reports queue is blocking the orders queue because you are using a simple sequential worker.
Your task:
- Modify your
config/horizon.phpfile to create a production environment configuration. - Set up a supervisor that handles all three queues:
orders,emails, andreports. - Implement the
autobalancing strategy to ensure theordersqueue is prioritized during spikes. - Configure the supervisor to use a total of 8 processes and a maximum of 3 retries per job.
- Explain in a brief comment in your code why
'balance' => 'auto'is preferable here over'balance' => 'simple'.
There are no comments for now.