Setting up Cronjob

I want to run some code that checks if a user’s membership has expired and send emails and make necessary changes to database automatically every day.

I believe I will have to setup a cronjob.

Any help on how I should set it up and what things to do and what things to not do?

Create a console command.

class SomeCommand extends CConsoleCommand {

    public function run($args) {

        echo "It runs!!\n";



Should be put in protected/commands.

Create a ‘console.php’ file in app root:


//$hostname = /$_SERVER['SERVER_NAME'];

// change the following paths if necessary



// remove the following lines when in production mode

//defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

//defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


$app = Yii::createConsoleApplication($config);


Do some test runs to see if it runs successfully:

(in protected):

./yiic your_command

(in site root):

php console.php your_command

then create a cron job for it:

/full/path/to/php /full/path/to/bugitor/console.php your_command

When it works over cron, make the script silent:

/full/path/to/php /full/path/to/bugitor/console.php your_command  >> /dev/null 2>&1