A queued job starts, runs for a while, and then is simply gone. There is no exception in your log and no stack trace. A minute or two later the same job either runs again or lands in failed_jobs with a message about being attempted too many times. Nothing in that message mentions memory, and memory is very often the cause.
This guide is about finding out what your Laravel queue jobs really use at their peak, and then fitting the worker inside a container that has a fixed memory limit. It applies to any host with a hard limit. Where we describe DeployBase, we say so, and those parts were read from our own configuration on 3 December 2026.
Three limits, three different failures
A queue worker lives under three separate memory limits. They fail in different ways, and only one of them tells you what happened.
| Limit | Who enforces it | What you see |
|---|---|---|
PHP memory_limit | PHP, per process | A fatal error that names memory (Allowed memory size of … bytes exhausted) in the process output |
queue:work --memory | The Laravel worker, between jobs | The worker finishes its current job, then exits with code 12 |
| The container or account limit | The Linux kernel | The process is killed outright. Exit code 137, and no message from PHP at all |
The second row is the one people misread. --memory=128 does not stop a job from using more than 128 MB. The worker only compares its memory with that number after a job has finished, and exits if it is over, so that a fresh process starts clean. A single job that needs 900 MB will sail straight past it.
The third row is the silent one. When the kernel kills a process, PHP gets no chance to write anything. The job stays reserved until retry_after passes (90 seconds in Laravel's default config/queue.php). Then the queue hands it out again. If the job has attempts left, it runs again and may be killed again. If it has none, Laravel fails it for exceeding its attempts. Either way, your own code never threw anything, which is why the log looks empty.
Measure the peak instead of guessing
You cannot size a worker from an average. You need the peak of the heaviest job. Laravel 13.45 made this a one-listener task: the JobAttempted event now carries a memoryUsage property. According to Laravel News, it holds the worker's peak memory in megabytes for that one job, the counter is reset before each job, and the event fires whether the job succeeded or failed.
The listener below is our own example, not Laravel's. Put it in the boot method of a service provider:
use Illuminate\Queue\Events\JobAttempted;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
Event::listen(function (JobAttempted $event) {
Log::info('job.attempted', [
'job' => $event->job->resolveName(),
'memory_mb' => round($event->memoryUsage, 1),
'ms' => round($event->duration),
'ok' => $event->successful(),
]);
});
Leave it running through a normal week, including the heavy days: the monthly export, the big import, the report that only one customer runs. Then read the highest memory_mb per job class. That figure, not the typical one, is what you plan for.
On an older Laravel version you can get the same figure yourself. PHP 8.2 added memory_reset_peak_usage():
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobFailed;
Event::listen(JobProcessing::class, fn () => memory_reset_peak_usage());
Event::listen([JobProcessed::class, JobFailed::class], function ($event) {
Log::info('job.peak', [
'job' => $event->job->resolveName(),
'memory_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 1),
]);
});
Two things this number does not include
- Other programs your job starts. The figure comes from PHP's own memory counter. If a job shells out to an image tool, a PDF renderer or a headless browser, that program's memory is counted by the kernel against your limit, but it is not in this number.
- A job that was killed. A process killed by the kernel never reaches the line that dispatches the event. So the worst job may be missing from your log entirely. If one job class shows attempts with no matching
job.attemptedline, treat that as the finding.
Turn a silent kill into a loud error
Once you know the peak, set PHP's own limit for the worker just above it. Then a job that grows beyond what you measured fails with a PHP error that names memory, instead of taking the kernel's route.
php -d memory_limit=256M artisan queue:work --stop-when-empty --max-time=50 --memory=128 --tries=3
What each part does:
-d memory_limit=256Mis the hard limit for this one PHP process. Check what you have today withphp -r 'echo ini_get("memory_limit");'; do not assume it.--memory=128makes the worker exit between jobs once it has grown past 128 MB. This is the cure for slow growth over many jobs, not for one large job.--tries=3puts a ceiling on attempts, so a job that keeps dying ends up infailed_jobswhere you can see it.--stop-when-emptyand--max-time=50make the worker exit on its own. The next section explains why that matters here.
The limit covers more than the worker
On most container hosts the memory limit is not the worker's alone. Work out what else shares it before you decide how much a job may use.
On DeployBase, each hosting account has one memory limit, and it is the plan's RAM figure: 1 GB on Starter, 2 GB on Pro, 4 GB on Business and 12 GB on Enterprise. Every container in the account counts toward that single total: the app container that serves your web requests, and any MySQL, PostgreSQL, Redis or MongoDB you run in the account. The kernel enforces the total. When it is reached, the kernel kills a process inside the account, and it chooses which one. It may be the queue worker. It may also be a PHP process serving a visitor, or the database.
So the sum that matters is:
peak of your heaviest job x workers running at the same time
+ what your web requests use at a busy moment
+ what your database and cache hold
+ headroom
must stay under the plan's RAM
If the heaviest job is 700 MB and the account has 1 GB, the answer is not a flag. The job has to get smaller, or the account has to get bigger.
Running the worker on DeployBase
The DeployBase dashboard does not have a process manager that keeps a worker running forever. What every plan does have is scheduled cron jobs, and a worker that drains the queue and exits fits that well. Add a cron job for your app in the dashboard:
Schedule: * * * * *
Command: php -d memory_limit=256M artisan queue:work --stop-when-empty --max-time=50 --memory=128 --tries=3
The command runs inside your app's container, in the app's own folder, so php artisan works as written. For each job created in the dashboard, the cron panel shows when it last started, its exit code and how long it took. Those exit codes now mean something:
- 0: the worker drained the queue or reached its time limit and stopped normally.
- 12: the worker stopped itself because it had grown past
--memory. Usually harmless; the next run starts fresh. - 137: the process was killed. With a memory limit in play, this is the one to investigate.
Be clear about what this setup costs you:
- Jobs can wait up to a minute. Cron starts a worker once a minute. A job dispatched just after a worker exits waits for the next one. If your app needs jobs to start within a second, this is the wrong shape for it.
- Long jobs overlap.
--max-timeis checked between jobs, so a job that runs for three minutes keeps its worker alive while cron starts the next ones. Two or three workers at once means two or three peaks at once. Count them in the sum above.
If overlap is a problem, let Laravel's scheduler hold the lock. Make the cron command php artisan schedule:run and define the worker in routes/console.php:
use Illuminate\Support\Facades\Schedule;
Schedule::command('queue:work --stop-when-empty --max-time=50 --memory=128 --tries=3')
->everyMinute()
->withoutOverlapping();
The trade is visibility: the cron panel then shows the exit code of schedule:run, not of the worker it started. Keep the JobAttempted listener in place so you still have your own record.
Making the peak smaller
Most oversized jobs are oversized for one of a few reasons, and each has a standard fix.
- Loading every row at once. Replace
Model::all()and largeget()calls withchunkById(),lazy()orcursor(). - Reading a whole file into a string. Read uploads and exports as streams, line by line or in blocks.
- One job doing the work of a thousand. Split it. A parent job that dispatches one small job per batch has a small, predictable peak.
- Growth across jobs. If memory rises job after job,
--max-jobs=100restarts the worker on a count, alongside--memory. - The query log. If something has enabled it in production, a long job stores every query it runs. Turn it off.
Measure again after each change. The listener costs one log line per job, so there is no reason to remove it afterwards.
A short checklist
- Log peak memory per job with
JobAttempted(Laravel 13.45 or later) or withmemory_reset_peak_usage(). - Collect a full business cycle and take the highest figure per job class.
- Add up job peak times concurrent workers, web requests, database and cache. Compare the total with your memory limit.
- Set
memory_limitfor the worker just above the measured peak, so that a surprise fails as a PHP error. - Set
--tries, so that a job which keeps dying becomes a visible failure. - Watch the worker's exit code. 137 means killed.
Sources: the memoryUsage property and its per-job behaviour are described in Laravel News, "Migration Durations and Job Memory Usage in Laravel 13.45", published 2 December 2026, and in Laravel framework pull request #62678; both read on 3 December 2026. Statements about DeployBase come from our own platform configuration and plan data, read the same day. DeployBase plans start at $5.99/month; see Laravel hosting on DeployBase.