2017 © Pedro Peláez
 

library cronos

Configure Cron task through PHP

image

mybuilder/cronos

Configure Cron task through PHP

  • Thursday, January 4, 2018
  • by mybuilder
  • Repository
  • 13 Watchers
  • 139 Stars
  • 32,835 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 14 Forks
  • 3 Open issues
  • 12 Versions
  • 4 % Grown

The README.md

Cronos

Easily configure cron through PHP., (*1)

If you use Symfony 4/5/6, you could use our cool bundle in order to configure your app jobs through fancy annotations!, (*2)

Setup and Configuration

Require the library via composer:, (*3)

composer require mybuilder/cronos

Usage

Build Cron

<?php

require 'vendor/autoload.php';

$cron = new MyBuilder\Cronos\Formatter\Cron;
$cron
    ->header()
        ->setPath('path')
        ->setHome('home')
        ->setMailto('test@example.com')
        ->setShell('shell')
        ->setContentType('text')
        ->setContentTransferEncoding('utf8')
    ->end()
    ->comment('Comment')
    ->job('/bin/bash command --env=dev')
        ->setMinute(1)
        ->setHour(2)
        ->setDayOfMonth(3)
        ->setMonth(4)
        ->setDayOfWeek(5)
        ->setStandardOutFile('log')
        ->appendStandardErrorToFile('error')
    ->end();

echo $cron->format();

That will print, (*4)

MAILTO=test@example.com
HOME=home
SHELL=shell
LOGNAME=logName
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 MyBuilder\Cronos\Formatter\Cron;
use MyBuilder\Cronos\Updater\CronUpdater;

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

$cronUpdater = CronUpdater::createDefault();
$cronUpdater->replaceWith($cron);

Troubleshooting

  • The current user must have a existing crontab file to use the updater, use crontab -e to create one.
  • When a cron line is executed it is executed with the user that owns the crontab, but it will not execute any of the users default shell files so all paths etc need to be specified in the command called from the cron line.
  • Your crontab will not be executed if you do not have usable shell in /etc/passwd
  • If your jobs don't seem to be running, check the cron daemon is running, also check your username is in /etc/cron.allow and not in /etc/cron.deny.
  • Environmental substitutions do not work, you cannot use things like $PATH, $HOME, or ~/sbin.
  • You cannot use % in the command, if you need to use it, escape the command in backticks.

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

The Versions

04/01 2018

dev-master

9999999-dev

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

04/01 2018

2.0.1

2.0.1.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

23/06 2016

2.0

2.0.0.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

04/06 2015

1.0.3

1.0.3.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

01/05 2015

v1.0.2

1.0.2.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

04/08 2014

v1.0.1

1.0.1.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

30/06 2014

1.0.0

1.0.0.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

06/05 2014

v0.9.1

0.9.1.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

29/10 2013

v0.9.0

0.9.0.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

28/10 2013

v0.8.2

0.8.2.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

28/10 2013

v0.8.1

0.8.1.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron

23/10 2013

v0.8.0

0.8.0.0

Configure Cron task through PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

php cron