The --stop-when-empty-for option keeps queue workers alive for a specific grace period after the queue empties, preventing rapid process churn during bursty workloads.
Running php artisan queue:work --stop-when-empty in serverless environments or container auto-scalers terminates the worker process immediately when no jobs remain. If new jobs arrive seconds later, new processes must spin up continuously.
The --stop-when-empty-for option adds a configurable idle timeout:
# Stops worker immediately once queue is empty
php artisan queue:work --stop-when-empty
# Keeps worker running for 60 idle seconds before exiting
php artisan queue:work --stop-when-empty-for=60
- Prevents process start/stop churn during intermittent job spikes
- Ideal for AWS ECS, Kubernetes HPA, and Serverless worker instances
- Retains database connection pooling while waiting for trailing jobs
Related Tips
View all tips →Monitor Aggregate Queue Metrics with Total Size Helpers in Laravel 13.27
Laravel 13.27 adds totalPendingSize(), totalDelayedSize(), and totalReservedSize() to the Queue facade, making it easy to aggregate queue metrics for dashboards and health checks.
Centralized Queue Routing with Queue::forward() in Laravel 13.26
Laravel 13.26 introduces Queue::forward() to reroute queued jobs to new queue names, different connections, or both without modifying job classes or dispatch sites.