>
Calling controller actions from cron and the comma...
Welcome, Guest

by Vinita on Friday, 21 November 2008
Calling controller actions from cron and the command line in cakephp framework


This is a very simple you can modify the dispatcher to call controller actions from the command line and cron. It's very simple. What you do is make a copy of index.php in /app/webroot/, call it cron_dispatcher.php and place it in /app. Scroll down in the code till you come to the line:- require CORE_PATH.'cake'.DS.'bootstrap.php'; Now replaces everything below it with the following code:- Download code // 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]); } What this means is you can call controller actions from the command line, so for example to call the send action in your mailouts controller you just create a cron job like this: php cron_dispatcher.php /mailouts/send As you can see it's a very simple approach that doesn't break the MVC framework. Since you are invoking your cron jobs as controller actions it is possible for users to invoke the action from the site proper. If there are certain actions that you don't want users to invoke add a line to the action to check that the constant CRON_DISPATCHER is defined. For example function send() { // Check the action is being invoked by the cron dispatcher if (!defined('CRON_DISPATCHER')) { $this->redirect('/'); exit(); } $this->layout = null; // turn off the layout // do something here }



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering