High memory usage with laravel queue
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Deciphering High Memory Usage in Laravel Queue Workers
As developers leveraging background job processing with Laravel queues, optimizing resource consumption—especially memory usage—is crucial for maintaining stable and cost-effective infrastructure. I’ve encountered a common scenario: running php artisan queue:work managed by Supervisor results in a persistent memory footprint, even when the queue is temporarily empty.
If you are seeing processes like your Laravel queue worker consuming significant memory (like the ~2GB observed in your example) while idle or during processing, it often points to how long-lived PHP processes manage their application state. Let’s dive into why this happens and how we can effectively manage these resource demands.
The Nature of Long-Lived Queue Workers
The core of the issue lies in understanding that queue workers are not ephemeral scripts; they are continuously running, long-lived processes. As the official Laravel documentation hints, these workers store the booted application state in memory. This state includes loaded classes, configuration files, service container bindings, and cached data necessary for the worker to execute jobs efficiently.
When a process boots up, it allocates a baseline amount of memory. Once that application context is established, the operating system often retains that memory until the process terminates completely. If you stop the queue work temporarily but don't restart the worker, this allocated memory remains reserved by the process, leading to high overall usage reported by tools like htop, even if no jobs are actively being processed at that moment.
Analyzing the Memory Consumption
The configuration you provided for Supervisor shows exactly this:
command=php /var/www/html/pharavel/artisan queue:work --max-time=10800 --timeout=10 --tries=1
This command executes the Laravel application environment repeatedly. Each time a worker picks up a job, it loads this entire context. If you are running multiple instances of these workers managed by Supervisor (even if configured for numprocs=1 initially), you multiply the memory overhead. The high baseline memory usage isn't necessarily a leak in the traditional sense, but rather the necessary overhead of keeping the framework and application state loaded in memory across many potential job cycles.
Strategies for Memory Optimization
Since we cannot eliminate the need for the worker to hold application context, our focus must shift to efficient resource management and tuning. Here are several practical steps to mitigate high memory usage:
1. Optimize PHP Configuration
Ensure your underlying PHP configuration is tuned for memory limits. While Laravel itself manages much of the overhead, ensuring PHP isn't overly aggressive in memory allocation can help. Review your memory_limit settings in php.ini. For long-running processes, setting appropriate limits prevents runaway allocations, although this must be balanced against the needs of the queued jobs themselves.
2. Fine-Tune Worker Execution (Batching)
If you are processing many small jobs sequentially, consider adjusting how often the worker checks for new jobs. While your current setup uses --max-time, ensuring that workers don't unnecessarily spin up and tear down context can help stabilize memory usage. Reviewing job batching strategies within your queue driver (e.g., Redis or database queues) can also impact how much memory is held during idle times.
3. Implement Memory Monitoring and Scaling
Instead of just accepting the high baseline, use monitoring tools to track memory growth over time. If you notice consistent, non-releasing increases in memory usage tied to job processing, it warrants a deeper investigation into potential application-level memory leaks within your specific job classes or service providers. For robust monitoring, integrating APM tools is highly recommended when dealing with complex background tasks managed by Laravel.
Conclusion
High memory usage in Laravel queue workers is often an artifact of long-lived processes holding the full application state in memory. It’s less about a classic memory leak and more about managing the overhead of maintaining an active framework environment across continuous execution cycles. By understanding this architecture, optimizing your PHP settings, and employing targeted monitoring, you can successfully manage these background workers efficiently, ensuring your infrastructure scales reliably, just as we aim for with modern frameworks like Laravel.