Configure Cron task through PHP

0.1.2 2016-05-15 19:09 UTC

This package is auto-updated.

Last update: 2021-02-28 10:40:17 UTC


Easily configure cron through PHP.

If you use Symfony 2, you could use our cool bridge in order to configure your app jobs in config!

Setup and Configuration

FDevsCron uses Composer, please checkout the composer website for more information.

The simple following command will install cron into your project. It also add a new entry in your composer.json and update the composer.lock as well.

$ composer require fdevs/cron

FDevsCron follows the PSR-4 convention names for its classes, which means you can easily integrate cron classes loading in your own autoloader.


Build Cron


require 'vendor/autoload.php';

use FDevs\Cron\Cron;
use FDevs\Cron\Model\Job;
use FDevs\Cron\Model\Time;
use FDevs\Cron\Model\Output;

$cron = new Cron();

$time = new Time();
$output = new Output();
$job = new Job('/bin/bash command', $time, $output);

    ->addHeader(Cron::HEADER_PATH, 'path')
    ->addHeader(Cron::HEADER_HOME, 'home')
    ->addHeader(Cron::HEADER_MAILTO, 'test@example.com')
    ->addHeader(Cron::HEADER_SHELL, 'shell')
    ->addHeader(Cron::HEADER_CONTENT_TYPE, 'text')
    ->addHeader(Cron::HEADER_CONTENT_TRANSFER_ENCODING, 'utf8')

echo strval($cron);

That will print


1    2    3    4    5    /bin/bash command --env=dev > log 2>> error

Updating Cron


require 'vendor/autoload.php';

use FDevs\Cron\CrontabUpdater;
use FDevs\Cron\Cron;

$cron = new Cron();
// $cron configuration...

$cronUpdater = new CrontabUpdater('unique_key');

Created by 4devs - Check out our blog for more insight into this and other open-source projects we release.