Cron Job in CakePHP 1.2

Monday, November 12th, 2007

After looking around the net for a way to execute cakephp scripts via a crontab I became fed up and made my own solution. I simply added a function to my existing controller and then executed it via a wget.

class PostsController extends AppController
function crontab {
// 404 if the request isnt from the localhost
if($_SERVER(’REMOTE_ADDR’) != ‘127.0.0.1′))
{
$this->cakeError(’error404′);
exit; // dont know if this is needed
}
// execute the cronjob
doSomething();
exit; // dont want to use a view
} // end controller

Now we just make a cron job to run every five minutes

wget –spider http://mydomain.com/posts/crontab