Workers
Run Laravel's queue, Celery or any long-running command beside your app. Up to 5 workers an app, each paying only for what it uses.
Updated 17 Oct 20263 min read
A worker is a second process of your app that runs all the time but never takes visits: a queue consumer, a bot, a script that watches something. It runs from your app's live version, with the same files and variables, and pays only for the memory and processor time it really uses. An app can have up to 5 workers.
An app's processes
| Process | How many | What it does |
|---|---|---|
| Web | One per app | Started with your start command. Visitors reach it on port 8080. |
| Workers | Up to 5 | Run all the time, beside the web process, for queues and other background work |
| Scheduled tasks | Up to 10 | Run a command on a timetable, then stop. See Scheduled tasks. |
You see them all on the app's page, under Processes. Each restarts by itself if it stops.
Add a worker
Open the app's page. Under Processes, choose Add a worker or scheduled task.
For Kind, choose Worker.
Give it a Name: lowercase letters, digits and dashes, starting with a letter, like
queue.Type its Command.
Under Limits, keep The app's limits, or choose Limits of its own.
Choose Save and restart.
The app restarts with its new worker, without downtime for your visitors. A worker added before the app's first deploy shows Waiting for a deploy until there's a live version to run.
Commands for common frameworks
| Framework | Worker command |
|---|---|
| Laravel | php artisan queue:work --tries=3 --max-time=3600 |
| Laravel Horizon | php artisan horizon |
| Django with Celery | celery -A shop worker --loglevel=info |
| Node.js with BullMQ | npm run worker, with a worker script in package.json |
--max-time=3600 makes Laravel's worker stop after an hour, and it starts again by itself: a simple way to free memory a long-running worker may hold.
Example: Asha's queue
Asha's shop sends its order emails from Laravel's queue, through a Valkey database used for queues. She adds a worker named queue with php artisan queue:work --tries=3 --max-time=3600 and the app's limits. When a customer orders, the web process puts the email on the queue and answers at once; the worker sends it a second later.
Her worker shows Running under Processes. Its lines appear in the project's logs, next to the web process's, so she can search for a failed job.
Limits and price
A worker uses The app's limits unless you give it Limits of its own. Either way, limits are only ceilings: it pays for the memory and processor time it really uses, every hour, like the web process. A worker that waits for jobs most of the time costs little. See Limits.
When a worker stops
A worker that stops is started again, after 1, 2, 4 seconds and longer, up to a minute apart. If it stops 5 times within 10 minutes, it shows Keeps crashing, we stop starting it, and you're told under the bell and, if you choose so in your alerts, by email. Deploy a fix, or start it again.
Things to know
A worker's files are the app's: changes it writes outside the permanent folders are gone on the next deploy.
A running worker keeps a sleeping app awake.
To look inside a running worker, open a terminal and choose it under Process.
To remove one, choose Remove: the app restarts without it.