Craft CMS 6 queue and scheduler

Published

Updated

Craft CMS 6 uses Laravel's queue and scheduler. Run both as jobs, outside the PHP processes that serve the site.

Queue

Craft CMS 6 queues long-running tasks such as image transforms, and with Craft 6 also password reset and email verification mails. The queue uses Laravel's database driver and the jobs table, which the post-deploy command php artisan migrate --force creates.

By default, Craft runs the queue through web requests, in the PHP processes that serve the site. Run it in a worker instead:

  1. Book the jobs component
  2. Add a worker with this command:
    php artisan queue:work --sleep=3 --tries=3 --max-time=3600
    
    shell
  3. Turn off the web-based queue runner in config/craft/general.php:
    ->runQueueAutomatically(false)
    
    php

--max-time restarts the worker every hour, which frees memory. See the Laravel queue guide for the options.

Scheduler

Craft CMS 6 registers tasks with Laravel's scheduler. On Craft Pro, craft:publish-releases publishes scheduled releases every minute, so a Pro site needs the cron job. On Craft Solo, Craft schedules nothing, and the cron job is only needed for scheduled tasks of the project itself. Add a cron job that runs every minute:

php artisan schedule:run
shell

php artisan schedule:list shows the registered tasks. The Laravel scheduler notes on runInBackground() and withoutOverlapping() apply to Craft 6 too.

The worker and the cron job are two jobs. Book a Jobs plan that holds two.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗