Aug 2024Infrastructure1 min read

Laravel Queue Worker on Shared Hosting

Shared hosting has no Supervisor or systemd, so Laravel's queue worker dies and stays dead. I wrote a Node.js process manager that starts the worker and restarts it whenever it exits, so queued jobs keep running.

Node.js supervisor that keeps php artisan queue:work alive without systemd

Node.js / PHP / Laravel

Problem

Laravel queues expect a long-running php artisan queue:work. Shared hosting usually has neither Supervisor nor systemd; bare SSH processes die when the session ends. Cron-every-minute is a poor substitute for a daemon.

On the hosts in play, Node.js could stay up via the panel’s process manager. The idea: let Node own persistence and spawn PHP as a child.

Solution

A ~50-line worker.js that:

  1. Spawns the queue worker with execa
  2. Pipes stdout/stderr to console and a timestamped log
  3. Restarts after exit with a configurable delay
  4. Reads Laravel path, log path, command, and delay from env vars

Decisions

  • execa over raw spawn for clearer promise-based handling
  • Restart via setTimeout so the event loop is not blocked
  • Env-only config: no bespoke config format between deploys

Used together with webhook-triggered deploy jobs on sites like school CMS.

What it demonstrates

  • Constraint-driven ops: use the runtime the host actually allows
  • Small tools over framework-heavy process managers for one job
  • Logging/stderr forwarding so failures are observable