Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code or a cronjob

Installs: 549

Dependents: 0

Suggesters: 7

Security: 0

Stars: 23

Watchers: 0

Forks: 1

Open Issues: 1


2.3.2 2020-02-21 14:29 UTC


Release Stars Downloads Issues Build Status Coverage Status Maintainability Demo Gitter Twitter

Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code or a cronjob.

TIP 1: The Janitor plugin can also perform other jobs than the build-in cache jobs.

TIP 2: It can also create logs of what it did.

TIP 3: It can also be used as an CLI.

  1. Custom Jobs
  2. Query Language
  3. Reload Panel
  4. Copy to Clipboard
  5. Open URL
  6. Download File
  7. Jobs from Classes
  8. CLI

Commerical Usage

This plugin is free but if you use it in a commercial project please consider to

Similar plugins

  • Kirby Terminal if you need to execute longer running processes on the terminal
  • Kirby Queue if you want to add scheduled jobs to queque which get trigged by a cron job


  • unzip as folder site/plugins/kirby3-janitor or
  • git submodule add site/plugins/kirby3-janitor or
  • composer require bnomei/kirby3-janitor


clean & loot

Usage Examples

PHP code

$success = janitor('clean'); // boolean
// or with context page and data
$json = janitor('clean', $page, 'ルパン三世', true); // array

Panel Field will create a clickable button

    type: janitor
    label: Clean Cache
    progress: Cleaning Cache...
    job: cleanCache
    type: janitor
    label: Enter Bank
    progress: Performing Heist...
    job: heist
    data: Grand # (string) forwarded to job context
    unsaved: false # button will be disabled if current page has unsaved changes


Predefined Jobs

  • flushPages calls flush() on kirbys core pages cache.
  • cleanCache removes all cache-files from custom caches or plugins.
  • cleanSessions triggers garbage collection for Sessions.
  • flushSessions removes all session-files.
  • flushLapse flushes cache used by lapse plugin.
  • flushRedisDB flushes DB used by redis cache driver plugin.

Custom Jobs

Go build your own jobs. Trigger APIs, create ZIPs, rename Files, ... check out the examples created for the unittests.

Extend with existing Jobs

Example: '' => ['bvdputte.kirbyqueue.queues'] will load all classnames or callbacks defined in option('bvdputte.kirbyqueue.queues') as well.


The data properties will be parsed for queries. You can use that to for example forward the current panel users email to your custom job.

  type: janitor
  label: Query '{{ }}'
  job: query
  data: '{{ }}'
'query' => function (Kirby\Cms\Page $page = null, string $data = null) {
    return [
        'status' => 200,
        'label' => $data, // this is the email

Panel Features

Context page and data

    type: janitor
    label: Perform Job
    progress: Performing Job...
    job: myjob
    data: my custom data
'page' => function(Kirby\Cms\Page $page = null, string $data = null) {
    // $page => page object where the button as pressed
    // $data => 'my custom data'
    return [
        'status' => 200,
        'label' => $page->title() . ' ' . $data,

Reload Panel View

'reload' => function(Kirby\Cms\Page $page = null, string $data = null) {
    return [
        'status' => 200,
        'reload' => true, // will trigger JS location.reload in panel

Copy to Clipboard

'clipboard' => function(Kirby\Cms\Page $page = null, string $data = null) {
    return [
        'status' => 200,
        'clipboard' => 'Janitor',

Open URL

'openurl' => function(Kirby\Cms\Page $page = null, string $data = null) {
    return [
        'status' => 200,
        'href' => '',

Download File

'download' => function(Kirby\Cms\Page $page = null, string $data = null) {
    return [
        'status' => 200,
        'download' => '',

ATTENTION: The download dialog will only appear at same origin otherwise it will behave like opening an url.

Jobs from Classes


    type: number
    default: 1
    min: 1
    type: janitor
    label: Apply Cheat
    progress: Applying Cheat...
    job: cheat
    data: 5
    type: janitor
    label: Start Invasion
    progress: Invading...
    job: invasion
    data: '{{ page.aliens.toInt }}'


return [
    '' => [
        '', // name of plugin option
    // rest of config


// use kirby load()-helper or composer to load your custom class
    'Space\\Invaders\\InvasionJob.php' => __DIR__ . '/classes/space/invaders/InvasionJob.php',

Kirby::plugin('space/invaders', [
   'options' => [
        'jobs' => [ // you custom jobs
            'cheat' => function(Kirby\Cms\Page $page = null, string $data = null) {
                // update add more aliens based on data
                $page->increment('aliens', intval($data));

                // then reload
                return [
                    'status' => 200,
                    'reload' => true, // will trigger JS location.reload in panel
            'invasion' => 'Space\\Invaders\\InvasionJob',
   // ... rest of your plugin



namespace Space\Invaders;

class InvasionJob extends \Bnomei\JanitorJob
     * @return array
    public function job(): array
        $page = $this->page();
        $data = $this->data();
        return [
            'status' => 200,
            'label' =>  $page->title()->value() . ' vs. ' . str_repeat('👾', intval($data)),


This plugin comes with an executable php script called janitor to use in the terminal/console. You can use it with an alias like this:

cd your/project/folder/root
alias janitor='php site/plugins/kirby3-janitor/janitor'
janitor --help

TIP: Depending on your OS you might need to make the script executable with chmod 0755 site/plugins/kirby3-janitor/janitor first.

TIP: If you are using a custom folder setup you need to tell the janitor where to get the kirby instance from like this janitor --kirby /public myJob. See Arguments below.

CLI Arguments

janitor --help

Usage: janitor [-f format, --format format (default: label)] [-h, --help] [-k kirby, --kirby kirby (default: /)] [-l, --list] [-v, --verbose] [job]

Kirby Instance Loader

The CLI needs to load the same Kirby Instance your website does. To achieve this the CLI attempts to create a special file named janitor-{HASH}.php based on your public index.php. It only comments out the echo statement.

CLI Examples

Examples based on the test from this plugin:

clean with dynamic progressbar

janitor --verbose cleanCache

Using Kirby instance from: {PROJECT}/janitor-7848cb3c7677f4ff109682b2d9cd9978d46f7de8.php
======================================================================> 100%

print as table

janitor --format table whistle

| status | 200 |
| label  | ♫   |

print as json and store as file

janitor --format json heist | cat > heist-$(date +%s).json
cat heist-1573147345.json

    "status": 200,
    "label": "7 Coins looted at Bank!"


bnomei.janitor. Default Description
jobs array of classnames or callbacks array of ['key' => function() { return []; } ]
jobs.extends [] array of names to other job definitions. example: ['bvdputte.kirbyqueue.queues']
label.cooldown 2000 in millisecondss. the field allow you to override this as well.
secret null any string or callback
log.enabled false if enabled it try to call Kirby-log Plugin

Usage in JS, Vue and as a Cronjob

Kirby API (post Authentification)

let janitor = fetch('')
  .then(response => response.json())
  .then(json => {

Kirby Vue

  .then(response => {


Set a secret in your config.php file and call the janitor api with secret in a crobjob like this. This way you do not need the Kirby API to authentificate.

wget --delete-after
// or
curl -s > /dev/null



This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.




It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.