Problem with console command


I tried to create a console command for cron, but I have a problem. I created the console command by guide and when cron executes, I have a message on my e-mail:

X-Powered-By: PHP/5.3.8

Content-type: text/html

No available commands.

Please define them under the following directory:


. I have the following cron command:

php /home/username/public_html/cron.php DeleteTmpFiles

. /cron.php


$yii = dirname(__FILE__) . '/../yii-1.1.9.r3527/framework/yii.php';

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

//defined('YII_DEBUG') or define('YII_DEBUG', true);



, /protected/config/cron.php


return array(

    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',

    'charset' => 'utf-8',

    'components' => array(

        'log' => array(

            'class' => 'CLogRouter',

            'routes' => array(


                    'class' => 'CFileLogRoute',

                    'logFile' => 'cron.log',

                    'levels' => 'error, warning',



                    'class' => 'CFileLogRoute',

                    'logFile' => 'cron_trace.log',

                    'levels' => 'trace',





    'import' => array(




    'name' => 'Cron',

    'params' => require(dirname(__FILE__) . '/params.php'),

    'preload' => array('log'),


, protected/commands/DeleteTmpFiles.php


class DeleteTmpFilesCommand extends CConsoleCommand


    public function run($args)





. What am I doing wrong?

I solved a problem. I had an error in the filename of command…

Following this example, the information what exactly was wrong with the filename.

The filename of the commands file should have been like this:


MyBlaClassCommand.php ->> The word ‘Command’ has to be at the end of the filename.

You can use yiic because it’s already provides functionality that you wrote in ./cron.php

Steps are:

  1. Create new command in protected/commands directory (just like you did)

  2. Configure protected/config/console.php (optional, you used ./protected/config/cron.php for this)

  3. Install new cron job /absolute/path/to/protected/yiic DeleteTmpFiles // command name here is case-insensitive so this would work too: deletetmpfiles