Laravel queue only run one job

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Why Your Laravel Queue Only Runs One Job on the Server: A Deep Dive As a senior developer working with distributed systems, one of the most common and frustrating issues encountered when deploying Laravel applications to a production server is the discrepancy between local development behavior and production execution. You observe that running `php artisan queue:work` on your local machine processes all queued jobs successfully, but when deployed to the server, it seems to stall or only handles a single job. This post will dissect why this happens, focusing specifically on database-backed queues, and provide actionable solutions based on best practices for robust queue management. ## The Root Cause: Environment vs. Process Management The behavior you are describing is rarely a bug within the Laravel queuing system itself; rather, it usually stems from how the process is executed on the server environment or subtle differences in resource handling between your local machine and the remote server. When running locally using `php artisan queue:listen` (or `work`), the operating system context is typically straightforward. However, when deployed on a server, several factors can introduce bottlenecks or misinterpretations: 1. **Process Persistence and Daemonization:** On a server, you often need to run queue workers persistently in the background, usually managed by tools like Supervisor or systemd. If you are simply running the command directly in an SSH session, the process might terminate or behave differently once the shell session ends. 2. **Database Connection Latency:** Database operations, especially when handling concurrent writes and locks (as happens with database queues), can introduce latency differences between environments. The server might be slower to establish or maintain the necessary database connections compared to your local setup. 3. **Resource Constraints:** Server environments often have stricter resource limits (CPU, memory) that can cause a worker process to pause or behave erratically if it hits a temporary resource ceiling before processing all available jobs. ## Database Queue Specifics: Why the Discrepancy? Since you are using the `database` queue driver, Laravel relies on reading jobs from your configured database table and locking them for processing. The issue often arises when the worker attempts to claim a job but encounters an environment or timing issue that causes it to fail after the first successful lock acquisition. For instance, if there is any slight delay in fetching the next batch of jobs due to network latency or slow database response on the server, the loop might terminate prematurely after processing one item, assuming no more work is immediately available. ## Solutions and Best Practices for Server Deployment To ensure reliable, concurrent job processing on a production server, you must move beyond simple command-line execution and implement proper process management. ### 1. Use Process Managers (The Essential Step) Never rely on running `php artisan queue:work` directly in an unmanaged shell session on a server. You need a robust daemon manager to ensure the worker keeps running even if SSH sessions drop or the script encounters minor errors. Use **Supervisor** or **systemd** to manage your worker processes. This ensures that if the process crashes, the manager automatically restarts it, providing true persistence. **Example using Supervisor configuration (Conceptual):** ```ini [program:laravel-worker] command=/usr/bin/php /var/www/html/artisan queue:work --queue=default --sleep=3 --tries=3 autostart=true autorestart=true user=www-data stdout_logfile=/var/log/supervisor/worker.log stderr_logfile=/var/log/supervisor/worker_err.log ``` ### 2. Optimize Worker Configuration For high-throughput systems, fine-tuning the worker settings can help mitigate latency issues: * **`--sleep=X`**: Increasing the sleep time (e.g., `--sleep=5`) gives the database more time to settle between job retrievals, which can improve stability on slower server connections, although it slightly reduces immediate throughput. * **`--tries=N`**: Ensure your jobs are configured with appropriate retry mechanisms. If a job fails and is not properly retried, it stops the worker from moving on to subsequent jobs. ### 3. Consider Alternative Drivers for Production While the `database` driver is excellent for development and testing because it's simple, for high-traffic production systems, consider switching to more robust drivers like **Redis** or **Beanstalkd**. These external services handle queuing outside of your primary application database, significantly reducing contention and improving overall system scalability. As Laravel documentation highlights the importance of choosing the right tool for the job when architecting scalable solutions, moving off file-based persistence to dedicated queue systems is a key architectural step (referencing best practices found on [laravelcompany.com](https://laravelcompany.com)). ## Conclusion The issue of queues running only once on a server is typically an orchestration problem rather than an application bug. By shifting your focus from simply executing a command in the terminal to implementing robust process management using tools like Supervisor, and by understanding how database interaction impacts queue locking, you can ensure that your Laravel queue workers operate reliably and concurrently in any production environment. Always prioritize stable service execution when deploying complex applications.