CakePHP Cron Dispatcher
While working with my team to develop a method whereby we can create cron jobs that inherit core functionality, database connections, etc. from the cakePHP framework, I found a blog post that discusses an elegant method to do just that. It is referred to as the “cron dispatcher”. It turns out, this method is very simple and works quite nicely. It provides access to all of the functions within the code set.
Here is the step-by-step set of instructions for implementation:
1. Make a copy of /app/webroot/index.php and rename it to /app/cron_dispatcher.php. (Note: You can actualy place this anywhere, you just need to make sure that the ROOT and APP_DIR constants are defined correctly.)
2. Open the newly renamed file and scroll down to the line: require CORE_PATH.'cake'.DS.'bootstrap.php'; and replace everything below it with:
// Dispatch the controller action given to it
// eg php cron_dispatcher.php /controller/action
define('CRON_DISPATCHER',true);
if($argc == 2) {
$Dispatcher= new Dispatcher();
$Dispatcher->dispatch($argv[1]);
}
(Note: You may opt to leave in the debug code [ if (DEBUG) {echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";} ])
3. Now you are ready to call your cakePHP driven APP via a cron job like: php cron_dispatcher.php /mailouts/send
The content here is taken liberally from the cakePHP bakery post that can be found here.









>
Follow Me (digitally you stalker)