Cronjobs

From EQdkp Plus
Jump to: navigation, search


Cronjobs for EQdkp Plus are written by php and are best-efford cronjobs, that means that EQdkp Plus tries to do execute a Cronjob at the predefined time, but it depends if a User visites the Eqdkp Plus Page or not.

Writing an Own Cronjob

New Cronjobs have to be placed in Folder /core/cronjobs/ of your EQdkp Plus Installation. As filename, you have to append _crontask.class.php, e.g. helloworld_crontask.class.php.

<?php
if ( !defined('EQDKP_INC') ){
	header('HTTP/1.0 404 Not Found');exit;
}

if ( !class_exists( "helloworld_crontask" ) ) {
	class helloworld_crontask extends crontask {
		public function __construct(){
			$this->defaults['repeat']	= true;
			$this->defaults['repeat_type']	= 'daily';
			$this->defaults['editable']	= true;
			$this->defaults['delay']	= false;
			$this->defaults['ajax']		= false;
			$this->defaults['description']	= 'MySQL Backup';
		}

		public function run(){
                        #If it's a plugin cronjob, uncomment the following line
                        #register('pm');
			echo "Hello World";
		}
	}
}
?>

As you can see, the Cronjobs overwrites the Defaults to set own settings. Also, he needs a run() method.

For more complex things, like own settings for the cronjob, please take a look at the existing cronjobs like backup_crontask.class.php.

Settings

	public $defaults = array(
		'start_time'		=> null, //Start Time of the cron, Timestamp
		'extern'		=> false, //Can be called by a real cronjob
		'ajax'			=> true, //Is executed by an Ajax Call (does not cause slow page loading)
		'delay'			=> true, //If execution time is not fulfilled, cron will be executed later. If false, the cron will be executed on next regularly execution time.
		'repeat'		=> false, //Repeat this cron
		'repeat_type'		=> 'hourly', //Repeat type, weekly, daily, hourly, ...
		'repeat_interval'	=> 1, //1 or 2 or 3 weeks/days/...
		'multiple'		=> false, //Runs the cron multiple times if it is delayed
		'active'		=> false, //Cron is active
		'path'			=> 'core/cronjobs/', //Path to Cronfile
		'params'		=> array(), //Params for Cronjob (set by User in Cronjob Settings)
		'editable'		=> false, //User can edit this Cronjob
		'description'		=> null //Description of the Cronjob
	);

Using a real Cronjob

You can also use a real cronjob, if you have access to the operating system functions. You have just to call the cronjob.php in the EQdkp Plus Root Directory, e.g. using wget.