Cronjobs Documentation
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:
- Make the file fuel/crons/ci_cron.php executable. This file will run the CodeIgniter bootstrap index.php file.
- Open up the fuel/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'].
- Make the file fuel/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/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:
// note that "/var/www/httpdocs/" is the path to your web server // using the CI 2.x CLI (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/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/crons/ci_cron.php backup/cron/1
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 my case, I needed to call to a php5/Applications/MAMP/bin/php5/bin/php. Here is a thread that talks about it more: http://codeigniter.com/forums/viewthread/130383/ Hopefully it saves you some time too!
Cronjobs Configuration
- crons_folder - the folder to save the cronjob file.
- cron_user - the user to associate the cronjob to.
- sudo_pwd - the sudo password if needed.