EN · $ USD
Developer and Application Servers

How to Run the Laravel Queue Worker and Scheduler on Shared Hosting

7 min read Updated: Sunucu Atlas technical team

In short

On cPanel hosting without Supervisor, the reliable way to run a Laravel queue worker is cron. One cron entry runs php artisan schedule:run every minute to trigger scheduled tasks, and a second entry starts a short-lived worker with queue:work --stop-when-empty that processes the queue and exits. Use the database queue driver.

In this guide
  1. Key concepts
  2. Why cron instead of an always-on worker?
  3. Prerequisites
  4. Step 1: Set the queue driver to database
  5. Step 2: Find the correct PHP path
  6. Step 3: Add the scheduler cron entry
  7. Step 4: Run the queue worker from cron
  8. Step 5: Align retry_after and timeout
  9. Step 6: Test and monitor
  10. What to do after a code update
  11. Common mistakes
  12. Limits of this approach
  13. Next step

A Laravel queue worker is normally kept running by a process manager such as Supervisor. Shared cPanel hosting has no Supervisor and no persistent background processes, so you use cron instead: one cron entry triggers scheduled tasks every minute with php artisan schedule:run, and a second entry starts a short-lived worker with php artisan queue:work --stop-when-empty that drains the queue and exits. This guide walks you through the setup, overlap prevention and common mistakes step by step.

Key concepts

  • Queue: Work such as sending e-mail, generating PDFs or calling an external API is taken out of the request and placed in a queue. The user gets a response right away, and the job is processed in the background.
  • Queue worker: The php artisan queue:work process that picks up jobs from the queue and runs them.
  • Scheduler: Laravel's task scheduling system. You define tasks in code, and a single cron entry on the server calls schedule:run every minute.
  • --stop-when-empty: The option that tells the worker to exit once the queue is empty. This is the key to running workers from cron.

Why cron instead of an always-on worker?

On shared hosting, processes you start end when your SSH session closes; processes pushed to the background with nohup can be killed by resource limits at any moment, and nothing restarts them. Cron, on the other hand, is a scheduler the provider guarantees. Every minute a new worker starts, finishes the jobs and exits. The trade-off: once a job lands in the queue, it can take up to about a minute to be processed. For notification e-mails, invoice PDFs and report generation, that delay is acceptable.

Prerequisites

  • SSH/Terminal access and Composer in cPanel
  • Your project uploaded to the server and working (if needed, see our guide on deploying a Laravel project to cPanel hosting)
  • The command-line PHP version matching the version your project requires

These come ready on Laravel hosting plans: cPanel Terminal/SSH access, Composer and Git, plus PHP versions up to 8.5.

Step 1: Set the queue driver to database

Redis usually isn't available on shared hosting, so the most robust option is the database driver. Set this line in your .env file:

QUEUE_CONNECTION=database

In Laravel 11 and later, migrations for the jobs and failed_jobs tables ship with the project. If an older project doesn't have the tables, create them and run the migration:

# Laravel 11 and later
php artisan make:queue-table
# Laravel 10 and earlier
php artisan queue:table

php artisan migrate

If you've cached your configuration, run php artisan config:cache again so the change takes effect.

Step 2: Find the correct PHP path

Cron doesn't carry over your terminal shell environment exactly, and a cron job running the wrong PHP version is the most common problem. Check with these commands over SSH:

which php
php -v

On cPanel servers, /usr/local/bin/php usually runs the version selected for your account. If you need to force a specific version, you can use the EasyApache path, for example /opt/cpanel/ea-php83/root/usr/bin/php. Confirm the path actually exists with ls.

Step 3: Add the scheduler cron entry

In cPanel, open Cron Jobs, set the schedule to "Once Per Minute" (* * * * *) and enter the command. Replace the kullanici (username) and proje (project) parts with your own path:

cd /home/kullanici/proje && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1

In Laravel 11 and later you define your tasks in routes/console.php; in older versions, in the schedule() method of app/Console/Kernel.php. If you're using the cPanel cron interface for the first time, our guide on setting up a cron job in cPanel shows the screens in detail.

Step 4: Run the queue worker from cron

There are two methods. The first is simpler and is the one we recommend.

Method A: A separate cron entry (recommended)

On the Cron Jobs screen, add a second entry that runs every minute:

cd /home/kullanici/proje && /usr/bin/flock -n /home/kullanici/proje/storage/queue.lock /usr/local/bin/php artisan queue:work --stop-when-empty --max-time=55 --tries=3 --timeout=50 >> /dev/null 2>&1

What each parameter does:

  • --stop-when-empty: The worker exits when the queue is empty and leaves no persistent process in memory.
  • --max-time=55: Even if the queue never empties, the worker exits after 55 seconds, so it doesn't overlap with the next minute's worker.
  • --tries=3: A failed job is attempted at most three times, then moves to the failed_jobs table.
  • --timeout=50: A single job is killed if it runs longer than 50 seconds.
  • flock -n: If the previous worker is still running, a new one isn't started at all. Keeping the lock file in the project directory instead of /tmp is more predictable on environments such as CloudLinux that use a per-user /tmp.

If flock isn't available on your server (which flock returns nothing), the --max-time value alone still prevents most overlap.

Method B: Through the scheduler

If you'd rather stick to a single cron entry, you can register the worker in the scheduler. For Laravel 11 and later, in routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('queue:work --stop-when-empty --max-time=55 --tries=3')
    ->everyMinute()
    ->withoutOverlapping()
    ->runInBackground();

runInBackground() matters: without it, schedule:run waits for the worker to finish and the other tasks in the same minute are delayed. withoutOverlapping() uses a cache lock, so make sure your cache driver (file or database) is working.

For Laravel 10 and earlier

In older versions, the same definition goes in the schedule() method of app/Console/Kernel.php:

protected function schedule(Schedule $schedule): void
{
    $schedule->command('queue:work --stop-when-empty --max-time=55 --tries=3')
        ->everyMinute()
        ->withoutOverlapping()
        ->runInBackground();
}

Don't use both methods at the same time; pick either the separate cron entry or the scheduler definition. If both run, two workers start every minute and needlessly eat into your account's process limit.

Step 5: Align retry_after and timeout

In config/queue.php, the retry_after value of the database connection (90 seconds by default) is how long a job can run before it's considered stuck and pushed back onto the queue. This value must always be greater than the worker's --timeout; otherwise a long-running job gets run a second time before it finishes, and the same e-mail goes out twice. In the example above, --timeout=50 and retry_after=90 are a safe pairing.

Step 6: Test and monitor

  1. Send a test job with Tinker: in php artisan tinker, dispatch() one of your own job classes.
  2. Check that the record appears in the jobs table and is removed within a minute.
  3. List failed jobs and retry them if needed:
php artisan queue:failed
php artisan queue:retry all

Use php artisan schedule:list to confirm your scheduled tasks are defined correctly. While debugging, temporarily replace >> /dev/null in the cron entry with >> /home/kullanici/proje/storage/logs/cron.log to see the output. Application errors are always written to storage/logs/laravel.log.

What to do after a code update

After pulling a new version with Git or uploading files, follow this order so workers don't process jobs with the old configuration:

cd /home/kullanici/proje
git pull
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan optimize
php artisan queue:restart

queue:restart tells running workers to finish their current job and exit; the signal is sent through the cache, so your cache driver must be working. Since cron workers live for a minute at most anyway, this command is usually just a safety measure, but making it a habit will make life easier when you move to a server.

Common mistakes

SymptomLikely causeFix
Jobs are never processedQUEUE_CONNECTION is still sync, or the config cache is staleFix the .env value, then run php artisan config:cache
Cron runs but throws errorsCron is using a different PHP versionUse the full PHP path
The same job runs twiceretry_after is lower than the timeoutIncrease retry_after
Hosting 508 resource limit errorMany overlapping workersUse flock and --max-time
Code changes aren't picked up by the workerA long-running worker is holding the old codeCron workers are replaced within a minute at most; run php artisan queue:restart if needed

Limits of this approach

A cron-based queue isn't suitable for jobs that must run within seconds, for Laravel Horizon or for WebSockets (Reverb). If you need those, move to a server with root access; we compare which infrastructure makes sense when in Laravel hosting vs. VDS. Laravel's official queue documentation lists every worker option.

Next step

Resource headroom matters if the queue and scheduler are to run smoothly on the same account alongside your other projects. The Sunucu Atlas SA-DEV-3 Laravel hosting plan gives you 4 GB of RAM, a 4-core processor, a 400% CPU limit, 80 GB of NVMe storage and 20 databases, so cron workers can run without slowing down your main site. For smaller projects, check out our other Laravel hosting options.

Frequently asked questions

Can I install Supervisor on shared hosting?

No. Supervisor requires root access and isn't available on shared hosting. Instead, you can build a reliable queue by running queue:work --stop-when-empty from cron every minute.

What does queue:work --stop-when-empty do?

The worker processes every job in the queue and exits on its own once the queue is empty. That way, workers started by cron don't leave persistent processes on the server.

How long are queued jobs delayed when using cron?

Because cron runs every minute, a job starts processing within about a minute at most after it lands in the queue. Jobs that need a response within seconds require an always-on worker on a server.

Is it a problem if two workers run at the same time?

The database driver locks jobs as it hands them out, so the same job won't go to two workers, but resources are wasted. It's best to prevent overlap with flock and --max-time.

How do I know the Laravel scheduler is running?

Run php artisan schedule:list to see your defined tasks and their next run times. Temporarily redirecting the cron output to a log file also confirms whether it's running.

For this guide

Recommended plans

With SSH, Composer and cron support, 4 GB of RAM and a 4-core processor, SA-DEV-3 gives you the headroom to run a cron-based queue worker and scheduler without slowing down your main site.

SA-DEV-3

cPanel
Recommended

80 GB NVMe disk

$1.37/mo

+VAT

  • Processor4 cores
  • Memory4 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-1

cPanel

40 GB NVMe disk

$0.69/mo

+VAT

  • Processor2 cores
  • Memory2 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-2

cPanel

60 GB NVMe disk

$0.98/mo

+VAT

  • Processor3 cores
  • Memory3 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

Laravel Hosting — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.