You trigger a background task in your Laravel app, but nothing happens. The job page says "Pending," and your database records remain unchanged. Then it hits you: in a containerized environment, background jobs do not run themselves. Without an active worker process listening inside the Sail container network, your queues are just dead files or silent Redis lists.
Running queue workers and task schedulers on your host OS will fail because they lack access to Sail's containerized databases, environment variables, and PHP extensions. To mirror production execution, you must run and manage your worker runtimes inside the Compose network.
In this guide, we show you how to configure queue connections, run workers and Horizon, handle job failures, and manage code updates without stale worker caches.
Navigation: All tools · Sail overview · Databases · Env & deploy · Troubleshooting
Table of contents
- Connections at a glance
- Running
queue:workin Sail - Horizon (Redis)
- RabbitMQ and AMQP packages
- Failed jobs and retries
- Code changes and
queue:restart - Scheduler (
schedule:run) - Contrast with production
- Common Mistakes
- Self-Check Questions
Connections at a glance
Select your queue driver in .env:
QUEUE_CONNECTION=redis
| Driver | Use case in Sail |
|---|---|
sync |
Debug job logic synchronously without starting a worker. |
database |
Simple async queue; requires running php artisan queue:table and a worker. |
redis |
Production-standard driver; integrates with Horizon; requires a Redis service. |
rabbitmq |
AMQP exchanges; requires a RabbitMQ sidecar container and community package. |
Note
Configuration caching
If you modify QUEUE_CONNECTION or any queue environment variables, run sail artisan config:clear or sail artisan config:cache to apply the changes to your running containers.
Running queue:work in Sail
To process jobs, open a dedicated terminal window and run:
# Terminal
sail artisan queue:work
For advanced controls, target specific connections and options:
# Terminal
sail artisan queue:work redis --queue=high,default --tries=3 --timeout=90
To run a single job and exit (useful for debugging):
# Terminal
sail artisan queue:work --once
Horizon (Redis)
Laravel Horizon provides a beautiful dashboard and code-driven configuration for Redis queues.
- Install Horizon via Composer:
bash
sail composer require laravel/horizon sail artisan horizon:install - Start Horizon inside your container:
# Terminal
sail artisan horizon
Access the dashboard at http://localhost/horizon. In development, Horizon stops when you press Ctrl+C.
RabbitMQ and AMQP packages
Laravel does not include a first-party RabbitMQ driver. To use AMQP:
- Add the RabbitMQ service to
docker-compose.yml(see Database recipes). - Install a community-maintained package (e.g.,
vyuldashev/laravel-queue-rabbitmq). - Set your connection details:
QUEUE_CONNECTION=rabbitmq
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
- Start processing:
bash
sail artisan queue:work rabbitmq
Failed jobs and retries
When a background job throws an exception, Laravel logs it to the failed_jobs table.
- List failed jobs:
bash
sail artisan queue:failed - Retry a specific job:
bash
sail artisan queue:retry 5 - Clear all failed jobs:
bash
sail artisan queue:flush
Code changes and queue:restart
Laravel workers boot the application once and process jobs in a continuous loop. If you edit a Job file, the running worker will continue executing the old code cached in memory.
Whenever you save changes to your codebase, restart the workers:
# Terminal
sail artisan queue:restart
Note
Autoreloading in Dev
To avoid typing queue:restart constantly during rapid local development, you can run the worker with the --max-jobs=1 or --once flags.
Scheduler (schedule:run)
Sail does not run a system cron daemon automatically. To run scheduled tasks in development, you have two options:
- Run the scheduler manually:
bash
sail artisan schedule:run - Run a continuous polling loop in the background:
# Terminal
sail run --rm laravel.test php artisan schedule:work
Contrast with production
| Topic | Sail (Local Dev) | Production Environment |
|---|---|---|
| Worker Manager | Manual terminal foreground | Supervisor or systemd daemon |
| Scaling | Single Docker container | Multiple containers / Kubernetes autoscaling |
| Failover | Manual container restart | Redundant nodes and clustering |
⚠️ Common Mistakes
1. Modifying Job code without restarting the worker
You fix a bug in your Job class, but the queue runner continues throwing the same error.
Reality: The worker has cached the old PHP files. Run sail artisan queue:restart.
2. Running php artisan queue:work on your host terminal
Running the command directly on your host machine will crash due to missing database drivers or an inability to resolve internal hostnames like redis or mysql.
Reality: Always prefix with sail to run inside the container environment: sail artisan queue:work.
3. Misunderstanding the sync queue driver
Using QUEUE_CONNECTION=sync runs jobs immediately inside the HTTP request lifecycle. This hides concurrency issues, timeouts, and serialization errors that will only appear in production.
Reality: Use database or redis locally to match production behavior.
🧠 Self-Check Questions
- Why does a running queue worker fail to execute new code changes you just saved to disk?
- What hostname should you write in your
.envfor RabbitMQ when running inside Sail? - How do you keep the Laravel task scheduler running continuously without setting up host-side cron jobs?
- Which artisan command do you run to re-queue a job that failed during execution?
Reveal Answers
- PHP CLI workers boot the entire application framework once and keep it in memory. They do not re-read files from disk for subsequent jobs. You must run
sail artisan queue:restart. - You must use the Compose service name, which is
rabbitmq. - Run
sail run --rm laravel.test php artisan schedule:work, which starts a long-running process that runs the scheduler every minute. - Run
sail artisan queue:retry {id}where{id}is the identifier from thefailed_jobstable orallto retry all failed jobs.