Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRON job for codeigniter

I am using codeigniter. I want to know how to set up a cron job to check a table for expiring users and insert data in to another table with the list of expiring users. How to do that.

When i tried to write a script with controller and model to insert the table:

Fatal error: Class 'Controller' not found in /home/content/html/test/live/application/controllers/cron.php on line 2

like image 379
ASD Avatar asked Feb 10 '10 11:02

ASD


People also ask

What is cron job in PHP?

The App Engine Cron Service allows you to configure regularly scheduled tasks that operate at defined times or regular intervals. These tasks are commonly known as cron jobs. These cron jobs are automatically triggered by the App Engine Cron Service.

What is in cron job?

A cron job is a Linux command used for scheduling tasks to be executed sometime in the future. This is normally used to schedule a job that is executed periodically – for example, to send out a notice every morning. Some scripts, such as Drupal and WHMCS may require you to set up cron jobs to perform certain functions.


2 Answers

You can find some more information on making CodeIgniter CLI-accessible here: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/

Next step is just using crontab -e to set up the cronjob.

like image 173
Zack Effr Avatar answered Oct 19 '22 02:10

Zack Effr


This might not be what you're looking for, but it works just fine for me:

Create your CRON job logic as a 'normal' controller function.

Then, in your standard, non-CI, PHP cronjob file just load the URL via

file_get_contents('http:example.com/cronjob/');

This will treat the URL as being hit just as by any other user and the entire CI framework will be at your disposal.

like image 31
Rid Iculous Avatar answered Oct 19 '22 02:10

Rid Iculous