Hi All,
Create cron.php file under project folder and write following:
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/console.php';
require_once($yii);
Yii::createConsoleApplication($config)->run();
?>
Create console.php file under protected/config folder and write same data as written in main.php. see below:
/ This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// preloading 'log' component
'preload'=>array('log'),
'import'=>array(
'application.components.*',
'application.models.*',
),
// application components
'components'=>array(
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=bollywood_news',
'emulatePrepare' => true,
'username' => $dbUsername,
'password' => $dbPassword,
'charset' => 'utf8',
'enableProfiling' => true,
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron.log',
'levels'=>'error, warning',
),
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron_trace.log',
'levels'=>'trace',
),
),
),
),
);
Now,
Create CronjobCommand.php file under protected/commands folder. Here cronjob is a command.
<?php
class CronjobCommand extends CConsoleCommand {
public function run($args) {
// your code will come here...
}
}
Now,
You have two ways to run your command:
Go to your project folder and write following:
a. php cron.php cronjob
b. php protected/yiic cronjob
Cheers!!!
?>