run a cron job with Yii using cmd

  1. database connection, in /protected/config/console.php

  2. for connection establish /protected/config/main.php File open select All or paste in console.php file

  3. then /protected/commands/SiteCommand.php

  4. below code paste in SiteCommand.php File


        class SiteCommand extends CConsoleCommand


          public function run($args)


       	echo 'hello yii friends';




  1. then open cmd

  2. \path\protected>yiic then press Enter Key

  3. then cmd show your commend name

  4. \path\protected>yiic site then press Enter Key

  5. show your output "hello yii friends".

[color="#008000"]NOTE: moved to proper section (Tips, Snippets and Tutorials instead of General Discussion for Yii 1.1.x)[/color]

Welcome to the Yii forum, you made a nice first post :)

Great; +1 for that!

Nice, clear and concise. +1

Nice one thanks. It helped me :)

Good one Buddy :)

It will workonly when you run from command prompt,cron job,means ,you have to add schedule a job,will execute on particular interval,For that I am using a extension from yiimann,yii-crontab

.By it,I have successfully scheduled cron jobs.