How to implement the command task processing method through Yii

Source: Internet
Author: User
This article mainly introduces the method that Yii implements command task processing, analyzes the steps and related techniques of yii configuration, loading and using command task processing with instance form, and needs friends to refer to

In this paper, the method of implementing command task processing by Yii is described. Share to everyone for your reference, as follows:

1. Configure the components required to perform the task

Task configuration file:/protected/config/console.php

The configuration method is similar to configuring the main file

<?php//the configuration for YIIC console application.//any writable Cconsoleapplication properties can be co nfigured here.return Array (' BasePath ' =>dirname (__file__). Directory_separator. '. ', ' name ' = ' My Console application ',//Application components//auto-loaded model and Component class ' Import ' =>a Rray (' application.models.* ',//Load all model classes ' application.components.* ' in the "application/models/" folder,//Load "application/com ponents/"folder all application component Classes ' application.extensions.* ',//load all the application component classes under the" application/extensions/"folder, ' components ' = Array (//uncomment the following to use a MySQL database ' db ' =>array (' connectionString ' = ' mys ') Ql:host=localhost;dbname=dbname ',//Connect MySQL database ' Emulateprepare ' to true, ' username ' = ' root ',//mys QL database user name ' password ' = ' 123456 ',//mysql database user password ' charset ' = ' UTF8 ',//mysql database code ' Tablepre Fix ' = ' zd_ ',//mysql database table prefix ' enableprofiling ' =>true, ' EnableparAmlogging ' =>true,),//load the email component ' mailer ' = = Array (' class ' = ' = ' application.extensions. Mailer. Emailer ',),);

2. Task file

Under the/protected/commands/file directory, inherit the Cconsolecommand base class for the task file naming method for the task name +command

such as gocommand.php

<?php/** * Autorun file */class Gocommand extends cconsolecommand{  /**   * dead Loop Output *   /public  function run () { C5/>for ($i =1; $i >0; $i + +) {      Self::echoword ($i);      Sleep (2);//sleep 2 seconds      //Jump      out if (i==500) {break;}}  }  /**   * Output Hollo Word   *  /Public Function Echoword ($i) {    echo "Hollo word--$i \ n";  }}

3. Perform tasks

Open the Command line tool, enter the project's/protected directory input YIIC command prompt, prompt list shows the task file just written

E:\project\app\protected>yiicyii Command Runner (based on Yii v1.1.12) usage:e:\zeee\zyd\protected\yiic.php < command-name> [Parameters ...]  The following commands is available:-go-mailqueue-message-migrate-shell-webappto see inpidual Command Help and use the Following:

Execute command YIIC go for task processing

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.