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
  • 602
  • 1
  • 10
  • 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

0 Answers0