PHP Classes
elePHPant
Icontem

PHP Cron Job Manager Script: Add PHP scripts to be executed periodically

Recommend this page to a friend!

  Author Author  
Name: Martin Pircher <contact>
Classes: 2 packages by
Country: Austria Austria
Age: ???
All time rank: 184816 in Austria Austria
Week rank: 181 Up1 in Austria Austria Up


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This package can add scripts to be executed periodically.

It can store and retrieve in a database details of scripts to be executed periodically.

An executor script can get retrieve the script jobs to be executed and creates new processes to execute the scripts using PHP CLI program.

It can also delete jobs, schedule the current job to a new time, enable or disable the execution of a job, prevent the execution of the same job multiple times.

Details
{startverticalbanner}
PHP Cronjob
===========================================

## Introduction ##

The cronjob php class allows PHP CLI scripts to register themself
to get executed within an to be set timeframe.

You will need crontab or similar to call an scheduler script ("executor")
which reads the jobs to be run and then forks them. A sample executor
using POSIX process control is provided.

The class provides ability to

* register and delete job from execution table
* schedule the current job to a new time
* enable/disable the execution of a job
* locking to prevent multiple execution of same job

For easy handling (installation and autoloader) a composer.json is
included but you also can simple include src/cronjob.php. The class
uses the namespace mplx\toolkit\cronjob.

To allow quick access to most basic functions a basic command
line tool is included.

## Requirements ##

* PHP 5.3+
* Crontab or similar to run scheduler script
* Recommended: Composer

## Getting Started ##

The easiest way to work with php-toolkit-cronjob is to install as a
Composer package inside your project. Composer isn't strictly
required, but makes life a lot easier.

If you're not familiar with Composer, please see <http://getcomposer.org/>.

A sample composer.json is provided below.

## Jobs ##

Documentation (`apigen -s src/,sample/ -d docs/`) is included in docs/.

### (un)register job ###

    public function registerJob($cmd, $interval, $jobid = '');
    public function unregisterJob($jobid = '');

### Reschedule ###

    public function scheduleJob($ts, $jobid = '');

### enable/disable job ###

    public function enableJob($jobid = '');
    public function disableJob($jobid = '');

### locking ###

    public function setLock($jobid = '');
    public function releaseLock($jobid = '');

### status ###

    public function getStatus($jobid = '');
    public function getScheduledJobs();

### helper: creating database table ###

    public function createTable()

## Commandline tool ##

A rudimentary command line tool is included to allow basic
functions to be performed directly from shell.

The first parameter has to be a PHP file with the
required database configuration (see `sample/config.inc.php`).

### create database table ###

    php bin/crontab sample/config.inc.php table create

###enable/disable job ###

    php bin/crontab sample/config.inc.php enable myjob
    php bin/crontab sample/config.inc.php disable myjob

### unlock job ###

    php bin/crontab sample/config.inc.php unlock myjob

### delete job ###

    php bin/crontab sample/config.inc.php delete myjob

### get full status of job ###

    php bin/crontab sample/config.inc.php status myjob

### list all registered jobs ###

    php bin/crontab sample/config.inc.php list
    php bin/crontab sample/config.inc.php list myjob
    php bin/crontab sample/config.inc.php list my%
    php bin/crontab sample/config.inc.php list %job%

## Usage ##

### composer.json ###

    {
       "name": "mplx/sample",
       "license": "proprietary",
       "description": "sample for installing php-toolkit-cronjob with composer",

       "repositories": [
            {
                "type": "vcs",
                "url": "https://mplx@bitbucket.org/mplx/php-toolkit-cronjob.git"
            }
        ],

        "require": {
            "mplx/php-toolkit-cronjob": "dev-master"
        }
    }

### sample usage with (composer) autoloader ###

    <?php

    $dbcfg=array(
        'user' => 'root',
        'password' => '',
        'type' => 'mysql',
        'host' => 'localhost',
        'database' => 'cronjob',
        'table' => 'sample_' . 'cronjobs'
    );

    $loader = require_once 'vendor/autoload.php';

    use mplx\toolkit\cronjob;

    $job = new CronJob('sched', $dbcfg);
    ...

### sample usage without autoloader ###

    <?php

    $dbcfg=array(
        'user' => 'root',
        'password' => '',
        'type' => 'mysql',
        'host' => 'localhost',
        'database' => 'cronjob',
        'table' => 'sample_' . 'cronjobs'
    );

    include dirname(__FILE__).'/vendor/mplx/php-toolkit-cronjob/src/cronjob.php';

    $job = new mplx\toolkit\cronjob\CronJob('sched', $dbcfg);
    ...

### sample job/executor ###

In /sample directory you'll find samples for

- simple PHP CLI script to be called (`samplejob.cli.php`)
- simple schedular script to be called by cron every few minutes (`executor.cron.php`)

To be able to run them you'll have edit the database credentials (`config.inc.php`)
and create the cronjob table (`setupdb.cli.php`).

You can run the job scheduler every 2 minutes from cron.

    # php cronjob scheduler
    MAILTO=dummy@dummy.tld
    *2 * * * *    root    /usr/bin/php /var/www/.../toolkit-cronjob/sample/executor.cron.php

## PHP Framework Interoperability Group standards recommendation (PSR) ##

Some effort has been made to refactore the old code to PSR compliance. The code
has been tested with PHP CodeSniffer (`phpcs --standard=PSR2 src/ sample/`). For more
information on PSR standards visit <https://github.com/php-fig/fig-standards>.

  Classes of Martin Pircher  >  PHP Cron Job Manager Script  >  Download Download .zip .tar.gz  >  Support forum Support forum (3)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Cron Job Manager Script
Base name: php-cronjob
Description: Add PHP scripts to be executed periodically
Version: 1.1.2
PHP version: 5.3.3
License: MIT/X Consortium License
All time users: 1390 users
All time rank: 2737
Week users: 3 users
Week rank: 240 Up
 
  Groups   Rate classes User ratings   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Time and Date Time and date values, formats and conversion View top rated classes
Group folder image Databases Database management, accessing and searching View top rated classes
Group folder image Unix Use of capabilities specific of POSIX, Unix like operating systems View top rated classes


  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (93%) Good (93%) Good (87%) Good (87%) - - Sufficient (73%) 179
Month: Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagedocs (17 files, 1 directory)
Files folder imagesample (4 files)
Files folder imagesrc (2 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file readme.md Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file crontab Appl. Auxiliary data

  Files folder image Files  /  docs  
File Role Description
Files folder imageresources (11 files)
  Accessible without login HTML file 404.html Doc. Documentation
  Accessible without login HTML file class-mplx.toolkit.cronjob.CronJob.html Doc. Documentation
  Accessible without login HTML file class-mplx.toolkit...CronJobCmdLine.html Doc. Documentation
  Accessible without login HTML file class-mplx.toolkit...njobDBAbstract.html Doc. Documentation
  Accessible without login HTML file class-mplx.toolkit...b.CronJobDBPDO.html Doc. Documentation
  Accessible without login HTML file class-mplx.toolkit...onJobInterface.html Doc. Documentation
  Accessible without login Plain text file elementlist.js Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login HTML file namespace-mplx.html Doc. Documentation
  Accessible without login HTML file namespace-mplx.toolkit.cronjob.html Doc. Documentation
  Accessible without login HTML file namespace-mplx.toolkit.html Doc. Documentation
  Accessible without login HTML file source-class-mplx....ronjob.CronJob.html Doc. Documentation
  Accessible without login HTML file source-class-mplx....CronJobCmdLine.html Doc. Documentation
  Accessible without login HTML file source-class-mplx....njobDBAbstract.html Doc. Documentation
  Accessible without login HTML file source-class-mplx....b.CronJobDBPDO.html Doc. Documentation
  Accessible without login HTML file source-class-mplx....onJobInterface.html Doc. Documentation
  Accessible without login HTML file tree.html Doc. Documentation

  Files folder image Files  /  docs  /  resources  
File Role Description
  Accessible without login Image file collapsed.png Icon Icon image
  Accessible without login Plain text file combined.js Data Auxiliary data
  Accessible without login Image file footer.png Data Auxiliary data
  Accessible without login Image file inherit.png Icon Icon image
  Accessible without login Image file resize.png Icon Icon image
  Accessible without login Image file sort.png Icon Icon image
  Accessible without login Plain text file style.css Data Auxiliary data
  Accessible without login Image file tree-cleaner.png Icon Icon image
  Accessible without login Image file tree-hasnext.png Icon Icon image
  Accessible without login Image file tree-last.png Data Auxiliary data
  Accessible without login Image file tree-vertical.png Icon Icon image

  Files folder image Files  /  sample  
File Role Description
  Accessible without login Plain text file config.inc.php Conf. Example script
  Accessible without login Plain text file executor.cron.php Example Example script
  Accessible without login Plain text file samplejob.cli.php Example Example script
  Accessible without login Plain text file setupdb.cli.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imagemplx (1 directory)
  Accessible without login Plain text file cronjob.php Aux. Class source
  Accessible without login Plain text file executor.php Example Class source

  Files folder image Files  /  src  /  mplx  
File Role Description
Files folder imagetoolkit (1 directory)

  Files folder image Files  /  src  /  mplx  /  toolkit  
File Role Description
Files folder imagecronjob (5 files)

  Files folder image Files  /  src  /  mplx  /  toolkit  /  cronjob  
File Role Description
  Plain text file CronJob.php Class Class source
  Plain text file CronJobCmdLine.php Class Class source
  Plain text file CronJobDBAbstract.php Class Class source
  Plain text file CronJobDBPDO.php Class Class source
  Plain text file CronJobInterface.php Class Class source

Install with Composer Install with Composer - Download Download all files: php-cronjob.tar.gz php-cronjob.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.