2017 © Pedro Peláez
 

library cron

Configure Cron task through PHP

image

fdevs/cron

Configure Cron task through PHP

  • Tuesday, September 13, 2016
  • by andrey1s
  • Repository
  • 4 Watchers
  • 0 Stars
  • 208 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Cron

Easily configure cron through PHP., (*1)

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

Setup and Configuration

FDevsCron uses Composer, please checkout the composer website for more information., (*3)

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., (*4)

$ 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., (*5)

Usage

Build Cron

<?php

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();
$time
    ->setMinute(1)
    ->setHour(2)
    ->setDay(3)
    ->setMonth(4)
    ->setDayOfWeek(5)
    ;

$output = new Output();
$output
    ->setOutFile('log')
    ->setErrFile('error');

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

$cron
    ->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')
    ->addJob($job)
    ;

echo strval($cron);

That will print, (*6)

MAILTO=test@example.com
HOME=home
SHELL=shell
PATH=path
CONTENT_TYPE=text
CONTENT_TRANSFER_ENCODING=utf8

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

Updating Cron

<?php

require 'vendor/autoload.php';

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

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

$cronUpdater = new CrontabUpdater('unique_key');
$cronUpdater->update($cron);

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

The Versions

13/09 2016

dev-master

9999999-dev

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

cron crontab

15/05 2016

0.1.2

0.1.2.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

cron crontab

14/05 2016

0.1.1

0.1.1.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

cron crontab

14/05 2016

0.1.0

0.1.0.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

cron crontab