Skip to content

Step 7 of 10

Run Laravel queues without SSH or Supervisor

Shared hosting has no Supervisor, and it stops long-running processes. So don't keep a worker running. Start one from cron, let it finish the queue, and let it exit.

The setup

  1. 1

    Set QUEUE_CONNECTION=database in .env.

  2. 2

    Make sure the jobs and failed_jobs tables exist. New Laravel installs create them with the default migrations.

  3. 3

    Add the schedule below, and the cron job from the previous chapter.

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

What each part does

  • --stop-when-empty exits once there is nothing left, so no process lingers.
  • --max-time=50 stops after 50 seconds, so one run ends before the next one starts.
  • --tries=3 gives up on a failing job after three attempts, and it goes to failed_jobs.
  • withoutOverlapping(10) stops two workers running together. The lock expires after 10 minutes, in case a run was killed.

If your cron runs every 5 minutes, use ->everyFiveMinutes(). Jobs then wait up to 5 minutes, which is fine for most emails.

Respect your email limit

Newsletters can use up your host's hourly email limit, and then password-reset emails fail too. Put bulk mail on its own queue, and process the important queue first:

queue:work --queue=default,newsletter --stop-when-empty --max-time=50

Frequently asked questions

Why not run queue:work from cron without --stop-when-empty?

Each run would keep going forever. Cron would start another every minute, until you hit your process limit and see 508 errors.

Can I run jobs without any queue?

Yes, QUEUE_CONNECTION=sync runs them during the request. It needs no cron, but visitors wait for slow jobs like emails.

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.