1

I tried to run CRON from Command Prompt. Its not working.

I have created cron.php in webroot which is copy of index.php, just change code

App::uses('Dispatcher', 'Routing');
define('CRON_DISPATCHER',true); 
if($argc == 2) { 
    $Dispatcher = new Dispatcher();
    $Dispatcher->dispatch(new CakeRequest($argv[1]), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
}

Now, I ran CRON in command prompt using

E:/wamp/bin/php/php5.4.12/php.exe E:/wamp/www/warehouse/admin/webroot/cron.php cron/test.

In my test function i wrote code,

$this->layout=null;

//Check the action is being invoked by the cron dispatcher 
if (!defined('CRON_DISPATCHER')) { $this->redirect('/'); exit(); } 
//$this->autoRender = false;

$my_file = 'E:/wamp/www/warehouse/admin/webroot/file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
$data = 'New data line 1';
fwrite($handle, $data);
fclose();
echo "success";
exit;

But its not create file in webroot and doesn't display any error.

Can anyone help me?

Jimesh Gajera
  • 612
  • 1
  • 11
  • 32
  • Its my mistake. Can we use cron_dispatcher in cakephp 2.4.7? – Jimesh Gajera Jun 11 '14 at 09:39
  • You _can_ as in it's technically possible, however **you definitely should not**. It's pretty pointless to use/write a cron dispatcher. – AD7six Jun 11 '14 at 09:57
  • possible duplicate of [How to setup cronjobs in cake php?](http://stackoverflow.com/questions/13949539/how-to-setup-cronjobs-in-cake-php) – AD7six Jun 11 '14 at 11:51

1 Answers1

0

I had the same problem and I added this in the controller, it worked fine

function beforeFilter() {
    parent::beforeFilter();
    $this->layout=null;
    $this->Auth->Allow('cron_getCountryId');
 }
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 18 '22 at 14:16