PHP Classes

PHP Cron Manager Class: Run scheduled tasks defined in a crontab file

Recommend this page to a friend!
  Info   View files Example   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 74%Total: 496 This week: 1All time: 5,846 This week: 560Up
Version License PHP version Categories
slobel-php-cron 1.0.2BSD License5.1PHP 5, Unix, Console, Parsers
Description 

Author

This package can run scheduled tasks defined in a crontab file.

It can parse a file in the crontab format that defines the times and the command lines strings of programs that are scheduled to run regularly.

The package can start parallel processes to run the scheduled tasks when time comes.

Picture of Dmitry Mamontov
  Performance   Level  
Name: Dmitry Mamontov <contact>
Classes: 16 packages by
Country: Russian Federation Russian Federation
Age: 33
All time rank: 78226 in Russian Federation Russian Federation
Week rank: 52 Up2 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 6x

Example

<?php
/**
 * phpcron
 *
 * Copyright (c) 2014, Dmitry Mamontov <d.slonyara@gmail.com>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * * Neither the name of Dmitry Mamontov nor the names of his
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package phpcron
 * @author Dmitry Mamontov <d.slonyara@gmail.com>
 * @copyright 2014 Dmitry Mamontov <d.slonyara@gmail.com>
 * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
 * @since File available since Release 1.0.0
 */
require_once 'lib/Autoloader.php';
Autoloader::register();
$cron = new PHPCron($argv);
$cron->run();


Details

PHPCron

PHPCron is a daemon to run tasks scheduled cron written in php, works similar to crontab

Requirements

  • PHP version 5.1 or higher.
  • Module installed "pcntl" and "posix".
  • All functions "pcntl" and "posix" removed from the directive "disable_functions".

Installation

Download the archive and extract.

wget https://github.com/dmamontov/crondaemon/archive/master.zip
unzip master.zip

or

git-clone https://github.com/dmamontov/crondaemon.git

Copy the folder "src" to the root of your project.

Entries cron

Create an entry in the file tasks/main.cron analogously to Example

/2  * php /var/www/data/public/cron/test.php test1
/5  * php /var/www/data/public/cron/test.php test2

More information about cron entry can be found here

Running the daemon

To start the daemon requires the console to run the script:

php /path/to/crondaemon.php parameter

or

/path/to/crondaemon parameter

Valid parameters

  • start [-f]
  • stop
  • restart
  • status
  • help

Connecting and starting the demon in your code

require_once 'lib/Autoloader.php';
Autoloader::register();
$cron = new CronDaemon($argv);
$cron->run();

  Files folder image Files  
File Role Description
Files folder imageexample (1 file)
Files folder imagesrc (2 files, 2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file main.cron Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageconfig (1 file)
Files folder imagelib (1 file, 2 directories)
  Accessible without login Plain text file phpcron Appl. Auxiliary data
  Accessible without login Plain text file phpcron.php Example Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Accessible without login Plain text file settings.ini Data Auxiliary data

  Files folder image Files  /  src  /  lib  
File Role Description
Files folder imageclasses (4 files)
Files folder imageinterfaces (1 file)
  Plain text file Autoloader.php Class Class source

  Files folder image Files  /  src  /  lib  /  classes  
File Role Description
  Plain text file Entries.php Class Class source
  Plain text file PHPCron.php Class Class source
  Plain text file Process.php Class Class source
  Plain text file Tools.php Class Class source

  Files folder image Files  /  src  /  lib  /  interfaces  
File Role Description
  Plain text file PHPCronInterface.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:496
This week:1
All time:5,846
This week:560Up
User Ratings User Comments (1)
 All time
Utility:95%StarStarStarStarStar
Consistency:90%StarStarStarStarStar
Documentation:95%StarStarStarStarStar
Examples:80%StarStarStarStarStar
Tests:-
Videos:-
Overall:74%StarStarStarStar
Rank:114
 
Please modify on symfony and prices would not be.
9 years ago (Vasiliy Trutov)
77%StarStarStarStar