Sorry, we don't support your browser.  Install a modern browser

Plugin API for cron/scheduled tasks#207

There are several things, where having a cron API would be very beneficial. From generating and optimizing thumbnails in the background to other media tasks, such as convertig video, which usually cannot be done on the fly. Other use cases include webmention processing (as seen in the commentions plugin), cache preloading or things, such as refreshing data retrieved from an external API or updating a search index.

Currently, every plugin handles these things on its own, which is not ideal and I think, this would be a great addition.

Running the cronjob could be possible in 2 ways:

$ php /path/to/site/index.php --url https://site.kirby/

When running from the command-line, a URL must be provided for Kirby to know, which config file to load. This is especially important for any feature, where url() is called (e.g. cache preloading).


Running via URL should have a configurable endpoint and a secret, so the (possibly resource-intense) job cannot be be triggered by anyone.

Plugins should be able to register their tasks/jobs/cronjobs whatsoever via a plugin endpoint, e.g.:

Kirby::plugin('my/plugin', [
  'tasks' => [
    'myTask' => function($feedback) {},

The $feedback variable is just a placeholder for an object, which allow the task to give feedback on whether it what successfull, statistics (e.g. “5 new pages added to search index”, “optimized 50 thumbnails and saved 5.8 MB” etc.). However, callback functions could also be called in the context of a feedback class instance, allowing them to use $this instead of a variable, which has been passed as a parameter.

This is just a rough draft, that can (and should) probably be turned into something much more sophisticated. But I think there are some real-world use-cases as listed above.

a month ago
Changed the title from "Cron/Maintenance API" to "Plugin API for cron/scheduled tasks"
a month ago