run a cron job with Yii using cmd

(Deepesh Saini111) #1
  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".

(Maurizio Domba Cerin) #2

[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 :)

(Jsfousseni) #3

Great; +1 for that!

(Jamessagan) #4

Nice, clear and concise. +1

(Zahoor Personal) #5

Nice one thanks. It helped me :)

(Tabrezsoft) #6

Good one Buddy :)

(Abhishek2890) #7

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.