How to run a CodeIgniter file through CRON? How to run a CodeIgniter file through CRON? codeigniter codeigniter

How to run a CodeIgniter file through CRON?


The simplest way to run a cron via CodeIgniter is to make a cron URL available via your app.

Then call it via wget

wget -O - -q -t 1 http://www.example.com/cron/run

Inside the controller you can then use a log to ensure the cron is not run too often i.e. if the Google robots trigger it by mistake.

A second method would be to use lynx

/usr/local/bin/lynx -source http://www.example.com/cron/run


You may also like to add --spider to ignore the response. This stops the request from timing out:

wget -O - -q -t 1 --spider http://www.example.com/cron/run


You might also want to check this out: Cron job bootstrapper

This is a simple bootstrapper file that you can use to directly run your CodeIgniter controllers from the commandline. It’s a very easy and elegant solution for using CI controllers for cron jobs. It also supports logging.