assume that the Yii project path is/home/apps/
1. Create a file/home/apps/protected/commands/crons.php
< span="">= '/home/apps/framework/yii.php '< span="">< span=""> < span=""> ( < span=""> < span="">< span="">(< span="">).' /.. /config/console.php '< span="">:: Createconsoleapplication (< span="">
2. Create the required profile/home/apps/protected/config/console.php, configure the required components, database connections, logs, and other information in a format similar to the main configuration file main.php
' 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 ' and ' = ') Phppdo ', ' connectionString ' = ' mysql:host=xxxx;dbname=xxx ', ' emulateprepare ' = = , ' username ' = > ' xxx ', ' password ' = ' xxx ', ' charset ' = ' utf8 ', ' tableprefix ' = ' tbl_ ', ,, ' PA Rams ' = (' params.php '),
3. Under/home/apps/protected/commands/new Testcommand class, Inherit Cconsolecommand, in Testcommand, you can use the project configuration information and the various methods of Yii
< span=""> testcommand < span=""> < span=""> < span=""> < span=""> < span=""> ...< span="">
4. Create a timed task
$ crontab-e
Insert
1 * * * */home/php/bin/php-f/home/apps/< span="">/commands/crons.php Test &
That is, the contents of the Testcommand class are executed for the first minute of the hour, similar to the other classes that can be created under/home/apps/protected/commands/and executed using the command line.
http://www.bkjia.com/PHPjc/749285.html www.bkjia.com true http://www.bkjia.com/PHPjc/749285.html techarticle assume that the Yii project path is/HOME/APPS/1. create file/home/apps/protected/commands/crons.php? = '/home/apps/framework/yii.php ' (= (). ' /.. /config/console.php ':: Createconsoleappli ...