Assume that the Yii project path is/home/apps/
1. Create a file/home/apps/protected/commands/crons. php
<? = '/home/apps/framework/yii.php'( = ().'/../config/console.php'::createConsoleApplication()->run();
2. Create the required configuration file/home/apps/protected/config/console. php to configure the required components, database connections, logs, and other information. The format is similar to the main. php configuration file.
<? 'basePath'=>().DIRECTORY_SEPARATOR.'..', 'name'=>'Emergency', 'import'=>'application.models.*', 'application.components.*', 'application.extensions.*',, 'components'=>'log'=>'class'=>'CLogRouter', 'routes'=>'class'=>'CFileLogRoute', 'levels'=>'info, warning, error',,,, 'db'=>'class'=>'application.extensions.PHPPDO.CPdoDbConnection', 'pdoClass' => 'PHPPDO', 'connectionString' => 'mysql:host=xxxx;dbname=xxx', 'emulatePrepare' => , 'username' => 'xxx', 'password' => 'xxx', 'charset' => 'utf8', 'tablePrefix' => 'tbl_',,, 'params' => ('params.php'),
3. Create a New TestCommand class under/home/apps/protected/commands/, inherit the CConsoleCommand,In TestCommand, you can use the configuration information of the project and various methods of Yii.
<? TestCommand ...
4. Create a scheduled task
$ crontab -e
Insert
1 * * * * /home/php/bin/php -f /home/apps//commands/crons.php Test &
That is, the content in the TestCommand class is executed in the first minute of every hour. Similarly, you can create other classes under/home/apps/protected/commands/and execute them using the command line.