Developing with: Crons

OUTDATED: USE https://jback.dev/x/EoA8


This guide requires knowledge on how to create plugins

I have received feedback that the crons only execute once:

This is intended behaviour, to make a repeating cron, you need to re-create a cronjob on each call in the cron.php. More about that below


With the latest Crisp update, plugins can now make use of the integrated cron system.

The usage is easy: create a file in includes/ with the name cron.php

Once you have done that, create a new cron where ever you want with the new Plugin::createCron function.

How to create cron programmatically:

<?php

$this->createCron("example_cron", "I am data!", "5 SECOND")

You have now created a new cron which executes your includes/cron.php

cron.php Environment

You can access cron info using $_CRON which contains the following data:

array(14) {
  ["ID"]=>
  string(5) "11701"
  ["Type"]=>
  string(19) "execute_plugin_cron"
  ["ScheduledAt"]=>
  string(19) "0000-00-00 00:00:00"
  ["CreatedAt"]=>
  string(19) "0000-00-00 00:00:00"
  ["FinishedAt"]=>
  string(19) "0000-00-00 00:00:00"
  ["UpdatedAt"]=>
  string(19) "0000-00-00 00:00:00"
  ["StartedAt"]=>
  string(19) "0000-00-00 00:00:00"
  ["Finished"]=>
  string(1) "0"
  ["Started"]=>
  string(1) "0"
  ["Canceled"]=>
  string(1) "0"
  ["Failed"]=>
  string(1) "0"
  ["Data"]=>
  object(stdClass)#54 (2) {
    ["plugin"]=>
    string(8) "cronjobs"
    ["data"]=>
    string(10) "I am data!"
  }
  ["Log"]=>
  NULL
  ["Interval"]=>
  string(8) "5 SECOND"
}

You can access the same functions as defined in the api/cron.php

2 Likes