FUEL CMS User Guide : Version 1.5.2


Cronjobs Module Documentation

This Cronjobs module documentation is for version 1.0.

Overview

Cron jobs (crontab) is a way to periodically execute tasks. For more information about cron jobs click here. You have 2 options now to run cron jobs.

The first is to use the ci_cron.php script that comes with FUEL and provides a few optional parameters you can set. To use this method, you must do the following:

  1. Make the file fuel/modules/cronjobs/crons/ci_cron.php executable. This file will run the CodeIgniter bootstrap index.php file.
  2. Open up the fuel/modules/cronjobs/crons/ci_cron.php and change the CRON_CI_INDEX. Optional constants to change are CRON_FLUSH_BUFFERS, CRON_TIME_LIMIT, $_SERVER['SERVER_NAME'], and the $_SERVER['SERVER_PORT'].
  3. Make the file fuel/modules/cronjobs/crons/crontab.php writable.

The cron folder should be protected by the .htaccess or live above the server's root directory.

The second option is to use the built in CLI (Command Line Interface) that was implemented in CI 2.x. This method only requires you to make the file fuel/modules/cronjobs/crons/crontab.php writable.

Database Backup

The backup module comes with a controller to backup the database with options to include the assets folder as well as email it as an attachment. Below is an example of the command to specify for a cron job to do that using both options mentioned above (requires the backup module installed):

Using the PHP Interpreter

// note that "/var/www/httpdocs/" is the path to your web server

// using the CI 2.x CLI and the php intepreter (Command Line Interface)
php /var/www/httpdocs/index.php backup/cron

// using the ci_cron.php script that comes with FUEL
php /var/www/httpdocs/fuel/modules/cronjobs/crons/ci_cron.php backup/cron

// adding a 1 at the end of the URI path will include the assets (if not specified in the config) and can be used with either method
php /var/www/httpdocs/fuel/modules/cronjobs/crons/ci_cron.php backup/cron/1

Using CURL or wget and a Webhook IP Address

If you are having trouble with using the php intepreter to run the script, you can also use CURL or wget to call the backup script. For it to work, you must set the webhook_remote_ip configuration parameter in the fuel/application/config/MY_fuel.php file to the server's IP address that is calling the script.

// using CURL
00 07 * * * curl http://www.mysite.com/backup/cron

// using wget
00 07 * * * wget http://www.mysite.com/backup/cron

If you are on a Mac and having trouble where the script is outputting nothing, you may need to make sure you are calling the right php binary. In our case, we needed to call /Applications/MAMP/bin/php/php5.x/bin/php.

If you are having issues with server variables not being set, there is an area in the index.php bootstrap file where you can set those:

if (defined('STDIN'))
{
	/* if your FUEL installation exists in a subfolder, then you may want to change SCRIPT_NAME to /subfolder/index.php 
	 (Needed for using Tester module if running via CLI) */
	$_SERVER['SCRIPT_NAME'] = 'index.php';
	$_SERVER['SERVER_NAME'] = 'localhost';
	$_SERVER['SERVER_PORT'] = 80;
	$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
}

Cronjobs Configuration

The following configuration parameters can be found in the modules/cronjobs/config/cronjobs.php configuration file. It is recommended that you copy the config file and place it in your fuel/application/config directory which will override the defaults and make it easier for future updates.

Property Default Value Description
crons_folder
CRONJOBS_PATH.'crons/'
directory for cronjobs relative to the install root

Libraries