Search by

beebmx / kirby-scheduler

beebmx

Scheduler offers a fresh approach to managing scheduled tasks on your server.

Package info

github.com/beebmx/kirby-scheduler

Type:kirby-plugin

pkg:composer/beebmx/kirby-scheduler

Fund package maintenance!

beebmx

Statistics

Installs: 336

Dependents: 1

Suggesters: 0

Stars: 18

Open Issues: 0

2.0.0 2026-11-27 18:26 UTC

This package is auto-updated.

Last update: 2026-11-27 18:28:36 UTC


README

Scheduler Logo

Build Status Total Downloads Latest Stable Version License

Scheduler for Kirby

This package enables Laravel Scheduler for your own Kirby applications.

According to Laravel Scheduler documentation, Scheduler offers a fresh approach to managing scheduled tasks on your server. The scheduler allows you to fluently and expressively define your task schedule within your application itself. When using the scheduler, only a single cron entry is needed on your server.

Scheduler

Overview

Compatibility

Version Kirby 4 Kirby 5 Kirby 6 PHP
2.x ✅ ✅ ✅ 8.4+
1.0.0 – 1.0.7 ❌ ✅ ❌ 8.3+

Note

Scheduler 2.x runs on PHP 8.4, 8.5 and 8.6, and supports illuminate/* 12 and 13 (13.2 or newer). On PHP 8.6, keep illuminate/* up to date (latest 13.x); older releases trigger deprecation notices.

Installation

composer require beebmx/kirby-scheduler

Important

There's no support for downloading the plugin manually. Please use Composer to install it.

Since Scheduler depends on Laravel Scheduler, and it uses some helpers from Illuminate/Support, you need to deactivate some helpers globally in your index.php file:

/*
 * In your index.php file, and before rendering Kirby, add the following lines.
 */
const KIRBY_HELPER_E = false;

Note

You can check the Kirby documentation for more information about helpers.

Note

Since 2.x, the namespace is Beebmx\KirbyScheduler. The Beebmx\KirbScheduler namespace from 1.x still works, but it's deprecated.

Usage

With Kirby Scheduler you have two ways to create your scheduled tasks:

Closure

This is the easiest way to create your scheduled tasks. You can define your scheduled tasks using a closure in the config.php file.

use Beebmx\KirbyScheduler\Schedule;

'beebmx.scheduler' => [
    'schedule' => function (Schedule $schedule) {
        $schedule->call(function() {
            //
        })->daily();
    },
],

File tasks

If you have many scheduled tasks, you can create a dedicated file to manage them. You can define the location of the file in your config.php:

use Beebmx\KirbyScheduler\Facades\Schedule;

'beebmx.scheduler' => [
    'tasks' => __DIR__.'/tasks.php'
],

Note

You can define the filename and location as you wish; just make sure to provide the correct path.

Then, in the tasks.php file, you can define your scheduled tasks:

<?php

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::call(function () {
    //
})->monthly();

Note

You can use both methods (Closure and File) at the same time if you need them.

Defining Schedules

Calling a Closure

You can schedule a closure using the call method on the Schedule instance to perform a task. In the following example, we schedule a closure to run daily at midnight:

use Beebmx\KirbyScheduler\Schedule;

'beebmx.scheduler' => [
    'schedule' => function (Schedule $schedule) {
        $schedule->call(function() {
            // Your task here
        })->daily();
    },
],

In addition to scheduling using closures, you may also schedule invokable objects. Invokable objects are simple PHP classes that contain an __invoke method:

$schedule->call(new PublishBlogEntry)->daily()->at('7:00');

Tip

You can specify different frequencies intervals for your scheduled tasks, such as hourly, daily, weekly, monthly, etc. Refer to the Schedule Frequency Options for a complete list of available scheduling frequency options.

Scheduling Shell Commands

The exec method may be used to issue a command to the operating system:

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::exec('node /home/forge/script.js')->daily();

Note

Shell commands run from your Kirby base directory.

Schedule Groups

When defining multiple scheduled tasks with similar configurations, you can use the group feature to avoid repeating the same settings for each task. Grouping tasks simplifies your code and ensures consistency across related tasks.

To create a group of scheduled tasks, invoke the desired task configuration methods, followed by the group method. The group method accepts a closure that is responsible for defining the tasks that share the specified configuration:

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::daily()
    ->group(function () {
        Schedule::call(new PublishBlogEntry);
        Schedule::exec('cp storage/log/log.txt storage/log/log-'.date('Y-m-d').'.txt');
    });

Timezones

Using the timezone method, you may specify that a scheduled task's time should be interpreted within a given timezone:

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::call(function () {
    //
})->timezone('Europe/Berlin')->at('2:00');

If you are repeatedly assigning the same timezone to all of your scheduled tasks, you can specify which timezone should be assigned to all schedules by defining a timezone option within in config.php file:

'beebmx.scheduler' => [
    'timezone' => 'Europe/Berlin',
],

Running the Scheduler

The schedule:run command will evaluate all of your scheduled tasks and determine if they need to run based on the server's current time.

So, when using Scheduler, we only need to add a single cron configuration entry to your server that runs the schedule:run command every minute:

* * * * * /path/to/cli/bin/kirby schedule:run >> /dev/null 2>&1

Important

schedule:run command depends on Kirby CLI. Make sure you have it installed and configured properly.

Running the Scheduler Locally

Typically, you would not add a scheduler cron entry to your local development machine. Instead, you may use the schedule:work command. This command will run in the foreground and invoke the scheduler every minute until you terminate the command. When sub-minute tasks are defined, the scheduler will continue running within each minute to process those tasks:

kirby schedule:work

Like a cron entry, every minute runs schedule:run in a new process, so changes to your config.php or tasks file are picked up without restarting the command.

Scheduling Commands

If you would like to view an overview of your scheduled tasks and the next time they are scheduled to run, you may use the schedule:list command:

kirby schedule:list

Sometimes you may want to test a specific scheduled task, without waiting for its scheduled time to arrive. You may use the schedule:test command with a named scheduled task to run the task immediately:

kirby schedule:test task-name

It's important that you assign a name to your scheduled tasks using the name method:

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::call(function () {
    //
})->monthly()->name('task-name');

Hooks

Scheduler provides these hooks:

  • beebmx.scheduler.run:before: This hook is executed before the scheduled tasks are run.
  • beebmx.scheduler.run:after: This hook is executed after the scheduled tasks are run. It receives the $failures of the run and its $output.
  • beebmx.scheduler.task:failed: This hook is executed every time a task fails. It receives the $task and the $exception.
use Illuminate\Console\Scheduling\Event;

'hooks' => [
    'beebmx.scheduler.task:failed' => function (Event $task, Throwable $exception) {
        // Log or notify the failure
    },
    'beebmx.scheduler.run:after' => function (array $failures, string $output) {
        //
    },
],

Failed Tasks

A failing task doesn't stop the run: the remaining tasks still run, and the failed ones are listed after the run:

  2026-11-27 10:15:00 Running [report] ......................... 0.02ms DONE
  2026-11-27 10:15:00 Running [cleanup] ........................ 0.01ms DONE

   ERROR  Scheduled task [report] failed: Connection refused.

You may react to a failure with the onFailure method (or to a success with onSuccess):

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::call(new SendReport)
    ->daily()
    ->name('report')
    ->onFailure(function () {
        // Notify someone
    });

Note

Laravel shows every task as DONE while it runs, so check the list after the run. You may also get the failures of the last run with Schedule::failures().

When tasks failed, schedule:run shows an error and exits with a non-zero code (1), so a cron monitor can detect it.

Note

The exit code requires Kirby CLI 2.x. Older versions show the error, but exit with 0.

Overlapping

To prevent a task from overlapping, or to run it on one server only, give it a name first:

use Beebmx\KirbyScheduler\Facades\Schedule;

Schedule::call(new SendReport)
    ->everyFiveMinutes()
    ->name('report')
    ->withoutOverlapping();

The locks are stored in your Kirby cache, in the schedule directory (site/cache/schedule by default).

Options

Option Type Default Description
beebmx.scheduler.tasks string null Define a path for external file.
beebmx.scheduler.schedule closure null Define a closure with tasks to perform with the runner.
beebmx.scheduler.timezone string UTC Define a global timezone for the scheduler

Here's an example of a full use of the options from the config.php file:

use Beebmx\KirbyScheduler\Schedule;

'beebmx.scheduler' => [
    'timezone' => 'America/Mexico_City',
    'tasks' => __DIR__.'/tasks.php',
    'schedule' => function (Schedule $schedule) {
        $schedule->call(function() {
            // ...
        })->daily();
    },
],

Kirby Blade

Scheduler works out of the box with Kirby Blade 7.x.

When Kirby Blade is installed, both plugins share the same container, so you can render Blade views inside your scheduled tasks:

use Beebmx\KirbyScheduler\Facades\Schedule;
use Beebmx\KirbyBlade\Template;

Schedule::call(function () {
    $report = Template::boot()->make('emails.report', ['date' => date('Y-m-d')])->render();

    // Send or store your report
})->daily();

Note

With the beebmx.kirby-blade.bootstrap option enabled (the default), Kirby Blade is booted before the scheduler starts. If you disable it, the scheduler boots Kirby Blade when it starts, so both plugins share the same configuration.

Kirby Blade is optional: Scheduler works the same without it, and when it's installed but not loaded as a plugin.

Testing

composer test

Since Kirby and illuminate/support both declare the e() helper, the test script disables Kirby's e() and dump() helpers before Composer loads them (see tests/constants.php). If you prefer the previous approach, which renames those helpers in vendor/getkirby/cms, run:

composer test-setup

The Kirby Blade integration tests only run when beebmx/kirby-blade is installed:

composer require --dev beebmx/kirby-blade --no-update
composer update
composer test -- --group=blade

License

Licensed under the MIT.

Credits