How to run yii commands periodically

Hi,

Does anyone know an elegant way to run yii commands periodically? I need to run a yii command or "script" say every minute to monitor files in a folder, and add their contents to a database used by the yii webapplication. This communication is enforced by a legacy system I cannot change.

I’m using yii on a Windows platform.

Thanks for any valuable comments.

Joeri

Hi,

I think you can do it via windows "scheduled task".

Thanks

Aruna

Ok, thanks. Now I just need to figure out how to create command without using the shell. I guess that is possible though I have never done that before.

Regards,

Joeri

This is how I execute console commands in linux crontab, Sameway you can use it on windows as well.

  1. Make a copy of <your app>/index.php and rename it as what ever name. in mine I named as console.php

  2. Then change


$config=dirname(__FILE__).'/protected/config/main.php';

to


$config=dirname(__FILE__).'/protected/config/console.php';

  1. Change

Yii::createWebApplication($config)->run();

to


Yii::createConsoleApplication($config)->run();

  1. now you can run your command in command prompt as

    first cd to your php.exe folder if run on windows otherwise no need

    then php /path/to/console.php <your command>

  2. In windows scheduler or linux crontab just add

    php /path/to/console.php <your command>