Search Sign in Write for us
PROMPTPOST

Software

Laravel Queues and Cron on Shared Hosting: What Actually Works

No Supervisor, no root, disabled PHP functions — and still a reliable background job system.

PromptPost Desk 6 min read
X Facebook LinkedIn
Published
Stacked server racks with a clock overlay representing scheduled jobs
Stacked server racks with a clock overlay representing scheduled jobs AI-generated image

Laravel's documentation assumes you can run a long-lived queue worker under a process manager like Supervisor. On a VPS that's easy. On shared hosting — still the cheapest way to put a Laravel app online — you usually can't.

That doesn't mean giving up on queues. Emails, image processing, sitemap generation and scheduled publishing all belong in the background, especially when a slow mail server can otherwise make a signup page hang for several seconds. You just need a setup designed around the platform's limits.

The core idea: a short-lived worker started every minute

Without a process manager, you can't keep a worker alive permanently. Instead, let cron start a fresh worker every minute that processes whatever is waiting and then exits:

php artisan queue:work --queue=mail,default --stop-when-empty --max-time=55 --tries=3
  • --stop-when-empty exits as soon as the queue is drained, so workers don't pile up.
  • --max-time=55 guarantees the worker exits before the next cron tick starts another one.
  • --queue=mail,default processes emails first, so a backlog of image jobs never delays a password-reset email.

Alongside it, run the scheduler every minute:

php artisan schedule:run

The trade-off: a job may wait up to a minute before it starts. For verification emails and scheduled posts that's perfectly acceptable — just tell users "it can take up to a minute to arrive."

Trap 1: the cron command format

This one cost real debugging time. The textbook cron line looks like this:

cd /path/to/app && php artisan schedule:run >> /dev/null 2>&1

On at least one popular shared host, commands written this way simply never ran the PHP part. A test job that appended the date to a file created an empty file once and never wrote to it again, while the same command worked perfectly over SSH.

What worked was the host's dedicated "PHP" cron type with an absolute path to artisan and no shell syntax at all:

/usr/bin/php /home/USER/domains/example.com/app/artisan schedule:run

Artisan doesn't need the working directory set; it locates the application from its own path. Output was then visible in the control panel's "view output" screen, which made debugging easy.

How to verify cron is really running: don't trust the panel listing. Check the job's output, look for rows leaving the jobs table, or schedule a test post a few minutes ahead and watch whether it publishes.

Trap 2: disabled PHP functions

Shared hosts disable risky functions by default. Two of them matter to Laravel:

  • proc_open — required by Composer's post-install scripts and by Laravel's scheduler, which runs each scheduled command as a subprocess. If it's disabled, composer install fails at package:discover and the scheduler fails on every run. Many hosts let you re-enable it from the PHP configuration panel.
  • exec and symlink — php artisan storage:link uses PHP's symlink() and falls back to exec(). With both disabled, create the link once over SSH with ln -s and make your deploy script tolerate the artisan command failing.

Only re-enable what you need. Leave exec, shell_exec and system disabled if your code doesn't require them.

Trap 3: duplicate jobs that multiply

When the worker wasn't running for a while, the backlog revealed a design flaw: 147 copies of the same "refresh sitemaps" job. Every publish or edit dispatched one, and nothing deduplicated them.

On a host where a worker might only get one minute at a time, wasted jobs are expensive. Make idempotent, repeatable jobs unique:

  • Implement ShouldBeUnique (or ShouldBeUniqueUntilProcessing) with a stable uniqueId() for jobs like sitemap refreshes, so a burst of twenty publishes produces one job.
  • Debounce them with a short delay so the burst collapses into a single run.
  • For per-record jobs, such as generating a social preview image, make the unique ID include the record and a fingerprint of the inputs.

Trap 4: jobs that take too long

Shared hosting often enforces CPU or execution limits. Design every job to finish well within a minute:

  • Set an explicit $timeout below your worker's --max-time.
  • Set an SMTP timeout in config/mail.php, so a hung mail server can't freeze a worker.
  • Chunk large operations and make them resumable, storing a cursor between runs.

Don't let mail block requests

Laravel's built-in verification and password-reset notifications are sent synchronously by default. On shared hosting, that means the signup request waits for the SMTP conversation to finish.

Queue them by extending the notifications with ShouldQueue, put every mailable on a dedicated mail queue, and dispatch after the database transaction commits, so a rolled-back action never sends an email.

Monitor the worker you can't see

The scariest failure mode is silent: the worker stops, nothing errors, and emails just quietly stop arriving. Add a health check that runs from the scheduler and alerts you when:

  • The oldest pending job is more than ten minutes old
  • The backlog exceeds a threshold
  • failed_jobs isn't empty

Send that alert synchronously rather than through the queue — a dead queue can't deliver its own obituary.

Is it worth it?

For a content site, a small SaaS or an internal tool, this setup is surprisingly solid: background email, image processing, scheduled publishing and maintenance tasks, all on a few-dollar hosting plan. When you outgrow the one-minute latency or the CPU limits, moving to a VPS with Supervisor is straightforward, because your jobs were already written to be short, idempotent and unique.

The rule of thumb: on shared hosting, assume nothing runs unless you've watched it run.

Related reading: Dev–prod parity lessons · SPF, DKIM and DMARC explained · How to brief an AI coding agent safely

Frequently asked questions

Can Laravel queues run on shared hosting?

Yes. Run php artisan queue:work --stop-when-empty --max-time=55 from cron every minute, alongside schedule:run. Jobs may wait up to a minute, which is fine for emails and background tasks.

Why is my Laravel scheduler not running on shared hosting?

Common causes are a cron format the host doesn't execute (cd … && … with redirection), a wrong PHP binary path, or proc_open being disabled. Use an absolute path to artisan and check the cron output.

Why does composer install fail with a proc_open error?

Composer's post-install scripts need proc_open. Many shared hosts disable it by default but let you re-enable it in the PHP configuration panel.

How do I stop duplicate jobs piling up in the queue?

Implement ShouldBeUnique or ShouldBeUniqueUntilProcessing with a stable uniqueId for repeatable jobs such as sitemap refreshes, and debounce them with a short delay.

The stream

All stories