How do I run console commands from different working directory?

Let’s say I want to run some of my commands by cron (I believe that’s what they were made for).

If I stay in my application root directory, where my index_console.php resides, it works fine. I issue


php5 index_console.php CountRatio

But when I try doing that from different directory, there are some problems.

if I issue


php5 /var/path/to/app/index_console.php CountRatio

it seems like php script runs ok, but no parameters is processed.


php5 '/var/path/to/app/index_console.php' CountRatio

does the same.

What am I doing wrong?

I just can guess that your /var/to/path might be incorrect…

You better create a custom yiic command. Check out this section from the guide:

http://www.yiiframework.com/doc/guide/1.1/en/topics.console

Check paragraph 1. on this page. All you actually have to do is create a custom command class and put it into protected/commands. Then you should be able to run that command with the local yiic copy.