Yii Creating timed tasks with console commands _php tutorial

Source: Internet
Author: User
Tags yii
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.