Build cron files from a config in your repository

v0.3.1 2020-09-18 12:12 UTC


Latest Version Latest Unstable Version Software License Build Status Coverage Status


$ composer require setono/cron-builder


The following two code snippets outlines the simplest usage of the cron builder.

1. Add your commands

The default directory to look for cronjobs is inside etc/cronjobs. This can be changed in the options of the CronBuilder.

Here we define two jobs. Two PHP commands that run on the given time.

# etc/cronjobs/jobs.yaml

- schedule: "0 0 * * *"
  command: "php first-script.php"

- schedule: "1 0 * * *"
  command: "php second-script.php"

2. Build the crontab

When your cronjobs are defined, you can build the crontab file:

use Setono\CronBuilder\CronBuilder;

$cronBuilder = new CronBuilder();
$crontab = $cronBuilder->build();

This will output the following:

###> Automatically generated by Setono Cron Builder - Do not edit ###
0 0 * * * php first-script.php
1 0 * * * php second-script.php
###< Automatically generated by Setono Cron Builder - Do not edit ###

You can save this in a file named crontab.txt and add it to your crontab like this:

$  cat crontab.txt | crontab -