There are certain tasks which can be better performed offline or using the console rather than using and online Web application. It is particularly tedious and time consuming when you use the web interface to do such task. Each request will have to download css, JavaScript files and you need to design a user interface to work with. Some tasks such as email sending, search indexing, and general cron jobs are better done using the console based approach.

One can write a PHP script to do all that. The difficulty here is making the scripts interact with your application. This could be in the area of accessing resources used by your web application. To overcome this, Yii provides an object-oriented console enabled framework making it easy to interacts with you web applications. The base class for this framework is the CConsoleApplication. CConsoleApplication together with CWebApplication share the same base class CApplication.

CConsoleApplication extends CApplication by providing functionalities specific to console requests. In particular, it deals with console requests through a command-based approach.

If you recall from our CApplication discussion, I mentioned one important method processRequest(),where the actual request processing work is done. The implementation of this method is one area where CConsoleApplication differs from CWebApplication. The user requests for CConsoleApplications have different format from normal web request made to a CWebApplication. The format for console request is

yiic <command-name> <action-name> --option1=value --option2=value2

The following properties are defined by the CConsoleApplication class.

commandMap property 
public array $commandMap;
//mapping from command name to command configurations.

commandPath property 
public string getCommandPath()
public void setCommandPath(string $value)
//the directory that contains the command classes. Defaults 
//to 'protected/commands'.

commandRunner property read-only 
public CConsoleCommandRunner getCommandRunner()
Returns the command runner.

CConsoleApplication responds to request using the CConsoleCommand. You can think of CConsoleCommand as the console version of CController. It passes the console request and dispatches it to the appropriate action.