Cron Job in CakePHP 1.2
November 12th, 2007 | by useful | in Programming |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

February 7th, 2008 at 4:27 am
nice post! a logical extension to this would be reporting tool showing the daily cron execution. Anyhow gr8 going.
February 7th, 2008 at 4:29 am
also maybe u can put that check for localhost to the beforeFilter method! this way u can add different actions in the controller (specifically for cron jobs)
March 28th, 2008 at 4:57 am
Hello !
I think you should check Shells and Tasks.
http://book.cakephp.org/view/110/creating-shells-tasks