Vishal Tyagi
← Projects
Infrastructure·shipped

Laravel Queue Worker on Shared Hosting

A small Node.js process manager that spawns and restarts Laravel's queue worker on shared hosting where Supervisor/systemd are unavailable.

Date2024-08
Reading TimeN/A
Statusshipped
StackNode.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; see also Webhook deploys without CI/CD.

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