PHP Classes

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

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (9 months ago) RSS 2.0 feedStarStarStarStar 67%Total: 1,714 All time: 2,295 This week: 41Up
Version License PHP version Categories
php-cronjob 1.1.11MIT/X Consortium ...5.3.3PHP 5, Time and Date, Databases, Unix
Description 

Author

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.

Picture of Martin Pircher
  Performance   Level  
Name: Martin Pircher <contact>
Classes: 2 packages by
Country: Austria Austria
Age: ???
All time rank: 165215 in Austria Austria
Week rank: 197 Up1 in Austria Austria Up

Details

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>.

  Files folder image Files (43)  
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 (43)  /  bin  
File Role Description
  Accessible without login Plain text file crontab Appl. Auxiliary data

  Files folder image Files (43)  /  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 (43)  /  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 (43)  /  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 (43)  /  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 (43)  /  src  /  mplx  
File Role Description
Files folder imagetoolkit (1 directory)

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

  Files folder image Files (43)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,714
This week:0
All time:2,295
This week:41Up
 User Ratings  
 
 All time
Utility:85%StarStarStarStarStar
Consistency:85%StarStarStarStarStar
Documentation:80%StarStarStarStarStar
Examples:80%StarStarStarStarStar
Tests:-
Videos:-
Overall:67%StarStarStarStar
Rank:468