How to call a controller/action in crontab?
Posted on: January 8, 2008
- In: ajax | cakephp | Developer
- 9 Comments
If you want to call a controller/action in crontab, you simply must:
1. create a copy of index.php in your app’s webroot directory,
and rename it to cron_dispatcher.php or to any filename.
2. after this, somewhere in line 78 of index.php of your app’s webroot directory,
put code:
$Dispatcher= new Dispatcher();
$Dispatcher->dispatch($argv[1]);
}
this code will get argument from php commandline having index = 1.
so, in your crontab,
* * * * php -q /var/www/html/cake/webroot/cron_dispatcher.php Controller/action
9 Responses to "How to call a controller/action in crontab?"
why not use lynx or wget command to call your script?
@brainv
Calling a script with lynx is OK for small tasks, but if you have a job which runs for many hours, the web server will potentially end the process. It’s usually much better to call it directly.
this was a year ago hahaha!
anyway,
@samoli, in that case, your code design need to review since it’s running to long for a web application.
my intension to use wget/lynx to call the url of your script is to simplify the task w/o configuring anything.
this was a year ago hahaha!
anyway,
@samoli, in that case, your code design need to review since it’s running too long for a web application.
my intension to use wget/lynx to call the url of your script is to simplify the task w/o configuring anything.
Nice article it works for me. thanks

February 11, 2008 at 11:37 pm
Could you also use cake console command and put a wrapper in vendors/shells directory to acheive the same effect?