Cronjobs - Scheduled code execution

Framelix have a built cronjob scheduler, that fires every 5 minutes. You can create your own Framelix/src/Cron.php class by extending the Console class Framelix/src/Console.php and by integrating the function runCron, as in this example.

The core itself have some default cronjobs, like database backups and removing old event logs.

As the job runs every 5 minutes, you surely need a way to say that it should do something only once a day, or every 3 hours, and so on. For this, we have a Framelix/src/Utils/Mutex.php which basically hold a Mutex for a given time period and then releases the Mutex automatically after that time.

All code that runs with this method is executed under the command line, independent of a frontend. Command line execution have unlimited lifetime by default, so you can run really heavy tasks in this process.

For example, we internally use this, to execute code only once every hour with this snippet.

Copy to clipboard