PHP Classes

PHP Cron Job Runner: Start and stop tasks in the background

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 453 This week: 1All time: 6,150 This week: 571Up
Version License PHP version Categories
cron-job-runner 1.0.0The PHP License5.0PHP 5, Language
Description 

Author

This package can start and stop tasks in the background.

The main class takes an object as parameter that will be used to implement common functionality of the task that is meant to be executed like the code to run when the task is started, stopped, when receiving new commands, etc..

Applications should extend the main class to implement the functionality of the background task that is going to be executed.

The class can start the task in the background in either Linux or Windows. It uses the PHP CLI version to execute the background task. It can take a custom php.ini configuration file.

The class can be started from the PHP CLI version or as Web server HTTP request. In the later in can preserve the super-global variables $_GET, $_POST, $_COOKIE, $_SESSION, $_FILES.

Picture of Bijaya Kumar  Behera
Name: Bijaya Kumar Behera <contact>
Classes: 6 packages by
Country: India India
Age: ???
All time rank: 56135 in India India
Week rank: 420 Up26 in India India Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

<?php
   
#####################<SETUP>###############################
   
define('DS', DIRECTORY_SEPARATOR);
   
define("CRON_ROOT_DIR", dirname(__FILE__) . DS );
   
define("CRON_TMP_DIR", CRON_ROOT_DIR . 'tmp' . DS );
   
define("CRON_BIN_DIR", realpath(CRON_ROOT_DIR . '..' . DS . '..' . DS . 'bin') . DS);
   
define("CRON_CLASS_DIR", realpath(CRON_ROOT_DIR . '../../systems') . DS );
   
define("CRON_CHANGE_DIR", @chdir(CRON_ROOT_DIR));
   
define("CRON_CUSTOM_PHPINI", realpath(CRON_ROOT_DIR . "../.configs"));

   
# Linux: /usr/local/bin/php, Window: D:/xampp/php/php.exe
   
define("CRON_PHP_PATH", 'D:/xampp/php/php.exe');
   
# Linux : /usr/bin/nohup, Window: CRON_BIN_DIR . 'nohup.exe' or COM or start or any custom exe
   
define("BG_RUN_COMMAND", 'start');

   
# Set name of the script
   
define('CRON_SERVICE_NAME', 'example-cron-job1' );
   
# Set log file name
   
define('CRON_LOG', CRON_TMP_DIR . 'example-cron-job1.log');
   
# Set output file name
   
define('CRON_OUTPUT_FILE', CRON_TMP_DIR . 'example-cron-job1.out');
   
# Set status file name
   
define('CRON_STATUS_FILE', CRON_TMP_DIR . 'example-cron-job1.status');
   
# Set stop file name
   
define('CRON_STOP_FILE', CRON_TMP_DIR . 'example-cron-job1.stop');
   
# Set pid file name
   
define('CRON_PID_FILENAME', 'example-cron-job1');
   
# Set pid dir path
   
define('CRON_PID_DIR', CRON_TMP_DIR );
   
# Set 1 for developing mode on , 0 for production mode on
   
define('DEVELOPING_MODE', 0);
   
# To run only one instance of this script set "1001" (any unique integer no);
    # To run only two instances of this script set "1001,1002,..." (any two unique integer no);
    # To run with no limits set as false
   
define('INSTANCES', "1001, 2001");
   
# false for disable, any value between 1- 100
   
define('LOAD_AVG_MAX', false); // false for disable, any value 1- 100
    #####################</SETUP>###############################

   
require_once( CRON_ROOT_DIR . ".classes" . DS . 'example-cron-job1.class.php');

   
// init
   
cronRunner::init( new exampleCronJob1CronService() ) ;

   
// run it
   
cronRunner::run();


Details

___ _ _ ___ ___ _ _ ___ | _ \ || | _ \/ __|_ _ ___ _ _ _ | |___| |__ | _ \_ _ _ _ _ _ ___ _ _ | _/ __ | _/ (__| '_/ _ \ ' \ | || / _ \ '_ \ | / || | ' \| ' \/ -_) '_| |_| |_||_|_| \___|_| \___/_||_| \__/\___/_.__/ |_|_\\_,_|_||_|_||_\___|_| PHPCron Job Runner 1.0.0 ------------------------------------------------------------------------------- Start and stop tasks in the background This package can start and stop tasks in the background. The main class takes an object as parameter that will be used to implement common functionality of the task that is meant to be executed like the code to run when the task is started, stopped, when receiving new commands, etc.. Applications should extend the main class to implement the functionality of the background task that is going to be executed. The class can start the task in the background in either Linux or Windows. It uses the PHP CLI version to execute the background task. It can take a custom php.ini configuration file. The class can be started from the PHP CLI version or as Web server HTTP request. In the later in can preserve the super-global variables $_GET, $_POST, $_COOKIE, $_SESSION, $_FILES. #################################### Features Summary: ********************** @ Support to run through command line @ Support to run through url request via http server (Apache) @ $_GET/$_POST/$_COOKIE/$_SESSION/$_FILES will perserve if you run through URL Request via http server (Apache) @ Custom error log @ External command listner @ Load Average check. @ OnStop/ onStart/ onFail / onValidate / onReceive callback implemnted @ Direct write debuger data to a output file @ Capture last error during end of excecution of the script @ Support currently activity to status file like "10 of 50 Steps are completed" @ support to run another extranal script @ Output response are form of text, json or xml ********************** !!!!! Required!!!!! ******************** 1. php binary executable file version >=5.3 (Obviously) 2. nohup binary executable file (in case of Linux) 3. temp folder must have write permission to all 4. php_com_dotnet.dll php extension should be enabled (in case of Window) [If not, No Problem, already added nohup.exe in bin folder] ********************* Example 1 Root service folder: crontabs [Place all your service inside this folder] Folder: ExampleCronJob1 [** temp folder with write permission should be created here] Filename: ExampleCronJob1.php --------- Simple cronjob that runs only one instance of the script defined in the script file i,e 1001 On Linux: /usr/bin/php crontabs/ExampleCronJob1/ExampleCronJob1.php -INSTID 1001 & On Window: bin\nohup.exe d:/xampp/php/php.exe crontabs/ExampleCronJob1/ExampleCronJob1.php -INSTID 1001 Through Browser: http://localhost/phpclasses/crontabs/ExampleCronJob1/ExampleCronJob1.php?3GCRON[SHELL]=1001&3GCRON[TESTMODE]=0&3GCRON[CONFIRM]=2&3GCRON[OUTPUT]=xml Params: 3GCRON[SHELL]=1001 for instance id of the script 3GCRON[TESTMODE]=1 1 for foreground, 0 for background 3GCRON[CONFIRM]=2 0-60 for wait until the service started 3GCRON[OUTPUT]='xml' or text;| or xml or json Example 2 Folder: ExampleCronJob2 Filename: ExampleCronJob2.php --------- This example of cron job demonstrate about how to start a script IN background when user request via web Also it preserves all data of $_GET/$_POST/$_SESSION/$_COOKIE/$_FILES Through Browser: http://localhost/crontabs/ExampleCronJob2/ExampleCronJob2.php Example 3 Folder: ExampleCronJob3 Filename: ExampleCronJob3.php -------- This example of cron job demonstrate how to validate a service before start On Linux: /usr/bin/php crontabs/ExampleCronJob3/ExampleCronJob3.php -INSTID 1001 & On Window: bin\nohup.exe d:/xampp/php/php.exe crontabs/ExampleCronJob3/ExampleCronJob3.php -INSTID 1001 Through Browser: http://localhost/phpclasses/crontabs/ExampleCronJob1/ExampleCronJob3.php?3GCRON[SHELL]=1001&3GCRON[TESTMODE]=0&3GCRON[CONFIRM]=2&3GCRON[OUTPUT]=json Params: 3GCRON[SHELL]=1001 for instance id of the script 3GCRON[TESTMODE]=1 1 for forground, 0 for background 3GCRON[CONFIRM]=2 0-60 for wait until the service started 3GCRON[OUTPUT]='json' or text;| or xml or json Example 4 folder : ExampleCronJob4 -------- Full example with:- @Read external command, @Default command ping, @Kill added On Linux: /usr/bin/php crontabs/ExampleCronJob3/ExampleCronJob3.php --INSTID 1001 & On Window: bin\nohup.exe d:/xampp/php/php.exe crontabs/ExampleCronJob3/ExampleCronJob3.php --INSTID 1001 Through Browser: http://localhost/phpclasses/crontabs/ExampleCronJob1/ExampleCronJob1.php?3GCRON[SHELL]=1001&3GCRON[TESTMODE]=0&3GCRON[CONFIRM]=2&3GCRON[OUTPUT]=json Params: 3GCRON[SHELL]=1001 for instance id of the script 3GCRON[TESTMODE]=1 1 for foreground, 0 for background 3GCRON[CONFIRM]=2 0-60 for wait until the service started 3GCRON[OUTPUT]='json' or text;| or xml or json

  Files folder image Files  
File Role Description
Files folder image.classes (1 file)
Files folder image.configs (1 file)
Files folder imagecrontabs (4 directories)
Files folder imagesystems (2 files)
Accessible without login Plain text file .gitignore Data Auxiliary data
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  .classes  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  .configs  
File Role Description
  Accessible without login Plain text file php.ini Data Auxiliary data

  Files folder image Files  /  crontabs  
File Role Description
Files folder imageExampleCronJob1 (1 file, 3 directories)
Files folder imageExampleCronJob2 (1 file, 3 directories)
Files folder imageExampleCronJob3 (1 file, 3 directories)
Files folder imageExampleCronJob4 (1 file, 3 directories)

  Files folder image Files  /  crontabs  /  ExampleCronJob1  
File Role Description
Files folder image.classes (1 file)
Files folder image.configs (1 file)
Files folder imagetmp (1 file)
  Accessible without login Plain text file ExampleCronJob1.php Example Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob1  /  .classes  
File Role Description
  Plain text file example-cron-job1.class.php Class Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob1  /  .configs  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob1  /  tmp  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob2  
File Role Description
Files folder image.classes (1 file)
Files folder image.configs (1 file)
Files folder imagetmp (1 file)
  Accessible without login Plain text file ExampleCronJob2.php Example Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob2  /  .classes  
File Role Description
  Accessible without login Plain text file example-cron-job1.class.php Example Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob2  /  .configs  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob2  /  tmp  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob3  
File Role Description
Files folder image.classes (1 file)
Files folder image.configs (1 file)
Files folder imagetmp (1 file)
  Accessible without login Plain text file ExampleCronJob3.php Example Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob3  /  .classes  
File Role Description
  Plain text file example-cron-job3.class.php Class Class source

  Files folder image Files  /  crontabs  /  ExampleCronJob3  /  .configs  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob3  /  tmp  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob4  
File Role Description
Files folder image.classes (1 file)
Files folder image.configs (1 file)
Files folder imagetmp (1 file)
  Accessible without login Plain text file ExampleCronJob4.php Example Example script

  Files folder image Files  /  crontabs  /  ExampleCronJob4  /  .classes  
File Role Description
  Plain text file example-cron-job4.class.php Class Class source

  Files folder image Files  /  crontabs  /  ExampleCronJob4  /  .configs  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  crontabs  /  ExampleCronJob4  /  tmp  
File Role Description
  Accessible without login HTML file index.html Data Auxiliary data

  Files folder image Files  /  systems  
File Role Description
  Plain text file cron_runner_class.php Class Class source
  Plain text file cron_service_class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:453
This week:1
All time:6,150
This week:571Up