Queue workers that keep running, on your own server.

A queue worker is a long-running command, such as php artisan queue:work, that has to be restarted when it exits and after every deploy. ServerDog runs each one as a systemd service on your server: it starts with the site’s first deploy, restarts five seconds after it stops, and restarts after each deploy so it picks up the new code. You add one from your Mac, with no Supervisor config to write.

By ServerDog. Updated .

Key facts

  • ServerDog runs each background process as a systemd service, as the site’s user, in the site’s live release.
  • A process restarts five seconds after it exits, and after every deploy and rollback unless you have stopped it.
  • The default Laravel queue worker is php artisan queue:work --sleep=3 --tries=3 --max-time=3600, on the site’s PHP version.
  • A process can run 1 to 16 copies. A copy asked to stop gets a minute to finish its job by default, and up to an hour.
  • Laravel sites have switches for Horizon, the Scheduler and Inertia SSR. Any other command can be added as a process.

Why does a queue worker need looking after?

A queue worker loads your application once and then waits for jobs. That makes it fast, and it creates two chores on a server. Something has to start the worker again when it exits, whether it crashed, ran out of memory or reached its time limit. And something has to restart it after each deploy, because a running worker keeps the old code in memory.

On a server you manage by hand, that means writing a Supervisor or systemd config for each worker and adding a restart to your deploy script. ServerDog does both for you.

How do I add a queue worker in ServerDog?

  1. Open the site, then Settings, then Processes.
  2. Choose Queue Worker. ServerDog fills in the command with the site’s PHP version.
  3. Change the options or the number of copies if you need to, and save.
php8.4 artisan queue:work --sleep=3 --tries=3 --max-time=3600

The server writes a systemd service for it and starts it in the site’s live release. A site that hasn’t been deployed yet starts its processes with the first deploy.

What can I set for each process?

Setting What it does
Command One line, such as php artisan queue:work. It runs in the site’s live release.
Copies 1 to 16. Each copy is its own service.
Directory A folder inside the release, for a monorepo. Empty means the release root.
Time to stop How long a copy may take to finish its job once asked to stop. A minute by default, up to an hour.

Each process shows how many copies are running and its recent output. You can stop one, and it then stays off, deploys included, until you start it again.

What happens to workers during a deploy?

  1. The deploy builds the new release and switches the site to it.
  2. The Laravel script’s last line, $RESTART_QUEUES(), runs artisan queue:restart and, if Horizon is installed, artisan horizon:terminate.
  3. The server restarts the site’s processes. Each copy gets its time to stop, so a job in progress can finish.
  4. The copies start again in the new release.

A rollback does the same in the other direction. Read how zero-downtime deploys work.

Which Laravel processes have a switch?

  • Horizon. Runs php artisan horizon, which starts and balances your queue workers itself.
  • Scheduler. Runs php artisan schedule:run every minute. Read how ServerDog runs cron jobs.
  • Inertia SSR. Runs php artisan inertia:start-ssr, if your build makes the SSR bundle.

Use Horizon or plain queue workers for a queue, not both. Horizon needs Redis, which ServerDog installs on app and cache servers.

Can I run something that isn’t a Laravel worker?

Yes. Choose Custom Command and enter any one-line command: a Symfony Messenger consumer, a Node script, a websocket server. It runs as the site’s user in the live release and is restarted with each deploy like any other process.

A command that belongs to no site goes in the server’s Processes tab instead. There you choose the Linux user and folder it runs in, and it keeps running through site deploys. A server can have up to 50 of these.

Why systemd and not Supervisor?

Both restart a command when it exits. ServerDog uses systemd because it is already running on every Ubuntu server, it stops each process within a set time, and its journal keeps each process’s output, which the app reads to show you recent lines. You don’t write or edit unit files; ServerDog generates them from the settings above.

What ServerDog does not do

  • It does not scale workers up and down by queue length. Horizon’s balancing does that for Laravel.
  • It does not show queued or failed jobs. Use Horizon’s dashboard or artisan queue:failed.
  • It does not export the site’s .env into the process. Laravel and most frameworks read the file themselves.

Go deeper

Questions

How do I keep a Laravel queue worker running on a VPS?

Run it under a process supervisor that restarts it when it exits, such as systemd or Supervisor. In ServerDog you add a queue worker in the site’s settings, and the server runs it as a systemd service that restarts five seconds after it stops.

Do I need Supervisor to run Laravel queues?

No. Supervisor is one way to keep php artisan queue:work alive; systemd, which every Ubuntu server already has, does the same job. ServerDog writes a systemd unit for each process, so there is no Supervisor config to maintain.

Are queue workers restarted when I deploy?

Yes. Queue workers are long-running, so they keep the old code in memory until they restart. ServerDog restarts a site’s processes after every deploy and rollback, and the Laravel script also runs artisan queue:restart and, with Horizon installed, horizon:terminate.

What happens to a job that is running when a worker restarts?

The worker is asked to stop and gets time to finish the job it is on: a minute by default, and up to an hour if you raise it. Only after that is it killed.

Can I run Laravel Horizon with ServerDog?

Yes. Laravel sites have a Horizon switch that runs php artisan horizon as a process. Horizon then starts and balances the queue workers itself, and deploys restart it.

Can ServerDog run workers that are not Laravel?

Yes. A process is any one-line command, so it can be a Symfony Messenger consumer, a Node script or a custom binary. Processes that belong to no site run from the server’s Processes tab.

Do workers keep running when my Mac is off?

Yes. Processes are systemd services on the server. Your Mac is only needed to change them or look at their output.

Last updated by ServerDog.

Your servers. Your Mac. Nothing in between.

For macOS 15 or later.