Home Backend Development PHP Tutorial Yii --Command task processing_PHP tutorial

Yii --Command task processing_PHP tutorial

Jul 14, 2016 am 10:11 AM
protected yii Task deal with perform tasks components Configuration Configuration file

1. Configure the components required to perform tasks
Task configuration file:/protected/config/console.php
The configuration method is similar to configuring the main file [html]

// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// application components

// Automatically loaded model and component classes
'import'=>array(
              'application.models.*',//Load all model classes under the "application/models/" folder
             'application.components.*', //Load all application component classes in the "application/components/" folder
             'application.extensions.*', //Load all application component classes in the "application/extensions/" folder
),

'components'=>array(
// uncomment the following to use a MySQL database
            'db'=>array(
                    'connectionString' => 'mysql:host=localhost;dbname=dbname',//Connect to the mysql database
                      'emulatePrepare' => true,
‘username’ => ‘root’,//MySQL database username
                    'password' => '123456',//MySQL database user password
                        'charset' => 'utf8',//MySQL database encoding
'tablePrefix' => 'zd_', //MySQL database table prefix
'enableProfiling'=>true,
                   'enableParamLogging'=>true,
),
//Load the Email component
             'mailer' => array(
'Class' = & gt; 'application.extersions.mailer.emailer',
),
),
);

// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// application components

// Automatically loaded model and component classes
'import'=>array(
'application.models.*',//Load all model classes in the "application/models/" folder
'application.components.*',//Load all application component classes in the "application/components/" folder
'application.extensions.*',//Load all application component classes in the "application/extensions/" folder
),

'components'=>array(
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=dbname',//Connect mysql database
'emulatePrepare' => true,
'username' => 'root',//MySQL database username
'password' => '123456',//MySQL database user password
'charset' => 'utf8',//MySQL database encoding
'tablePrefix' => 'zd_', //MySQL database table prefix
'enableProfiling'=>true,
‘enableParamLogging’=>true,
),
//Load Email component
'mailer' => array(
'class' => 'application.extensions.mailer.EMailer',
),
),
);2.Task file
Place it in the /protected/commands/ file directory and inherit the CConsoleCommand base class as a task file. The naming method is Task name+Command
For example GoCommand.php[html]

/**
* Automatically run files
​*/
class GoCommand extends CConsoleCommand
{


/**
* * Infinite loop output
​​*/
Public function run(){
                                   
for($i=1;$i>0;$i++){
               self::echoWord($i);
             sleep(2);//Sleep for 2 seconds
                                                                                  // Jump out
If(i==500){
break;
                                                                                                                                               } 
}  

/**
* Output hollo word
​​*/
Public function echoWord($i){
echo "hollo word --$in";
}  
}

/**

* Automatically run files

​*/
class GoCommand extends CConsoleCommand
{

/**

* Infinite loop output
​*/
public function run(){

for($i=1;$i>0;$i++){
self::echoWord($i);
Sleep(2);//Sleep for 2 seconds
 
//Jump out
if(i==500){
Break;
}
}
}

/**

* Output hollo word

​*/
public function echoWord($i){
echo "hollo word --$in";
}
}3.Perform tasks
Open the command line tool, enter the /protected directory of the project, enter the yiic command, and a prompt will appear. The prompt list displays the task file just written [html]
E:projectappprotected>yiic
Yii command runner (based on Yii v1.1.12)
Usage: E:zeeezydprotectedyiic.php [parameters...]

The following commands are available:
- go
- mailqueue
- message
- migrate
- shell
- webapp

To see individual command help, use the following:

E:projectappprotected>yiic

Yii command runner (based on Yii v1.1.12)

Usage: E:zeeezydprotectedyiic.php [parameters...]

The following commands are available:

- go

- mailqueue
- message
- migrate
- shell
- webapp

To see individual command help, use the following:Execute the command yiic go to achieve task processing


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477288.htmlTechArticle1. Configuration, component task configuration file required to execute the task: /protected/config/console.php Configuration method Similar to configuring the main file [html] ?php // This is the configuration for yi...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to pass the Imperial Tomb mission in Goat Simulator 3 How to pass the Imperial Tomb mission in Goat Simulator 3 Mar 11, 2024 pm 01:10 PM

Goat Simulator 3 is a game with classic simulation gameplay, allowing players to fully experience the fun of casual action simulation. The game also has many exciting special tasks. Among them, the Goat Simulator 3 Imperial Tomb task requires players to find the bell tower. Some players are not sure how to operate the three clocks at the same time. Here is the guide to the Tomb of the Tomb mission in Goat Simulator 3! The guide to the Tomb of the Tomb mission in Goat Simulator 3 is to ring the bells in order. Detailed step expansion 1. First, players need to open the map and go to Wuqiu Cemetery. 2. Then go up to the bell tower. There will be three bells inside. 3. Then, in order from largest to smallest, follow the familiarity of 222312312. 4. After completing the knocking, you can complete the mission and open the door to get the lightsaber.

The operation process of WIN10 service host occupying too much CPU The operation process of WIN10 service host occupying too much CPU Mar 27, 2024 pm 02:41 PM

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

The working principle and configuration method of GDM in Linux system The working principle and configuration method of GDM in Linux system Mar 01, 2024 pm 06:36 PM

Title: The working principle and configuration method of GDM in Linux systems In Linux operating systems, GDM (GNOMEDisplayManager) is a common display manager used to control graphical user interface (GUI) login and user session management. This article will introduce the working principle and configuration method of GDM, as well as provide specific code examples. 1. Working principle of GDM GDM is the display manager in the GNOME desktop environment. It is responsible for starting the X server and providing the login interface. The user enters

Where can I find Douyin fan group tasks? Will the Douyin fan club lose level? Where can I find Douyin fan group tasks? Will the Douyin fan club lose level? Mar 07, 2024 pm 05:25 PM

TikTok, as one of the most popular social media platforms at the moment, has attracted a large number of users to participate. On Douyin, there are many fan group tasks that users can complete to obtain certain rewards and benefits. So where can I find Douyin fan club tasks? 1. Where can I view Douyin fan club tasks? In order to find Douyin fan group tasks, you need to visit Douyin's personal homepage. On the homepage, you will see an option called "Fan Club." Click this option and you can browse the fan groups you have joined and related tasks. In the fan club task column, you will see various types of tasks, such as likes, comments, sharing, forwarding, etc. Each task has corresponding rewards and requirements. Generally speaking, after completing the task, you will receive a certain amount of gold coins or experience points.

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

Learn how to handle special characters and convert single quotes in PHP Learn how to handle special characters and convert single quotes in PHP Mar 27, 2024 pm 12:39 PM

In the process of PHP development, dealing with special characters is a common problem, especially in string processing, special characters are often escaped. Among them, converting special characters into single quotes is a relatively common requirement, because in PHP, single quotes are a common way to wrap strings. In this article, we will explain how to handle special character conversion single quotes in PHP and provide specific code examples. In PHP, special characters include but are not limited to single quotes ('), double quotes ("), backslash (), etc. In strings

Where is the win10 user profile? How to set the user profile in Win10 Where is the win10 user profile? How to set the user profile in Win10 Jun 25, 2024 pm 05:55 PM

Recently, many Win10 system users want to change the user profile, but they don’t know how to do it. This article will show you how to set the user profile in Win10 system! How to set up user profile in Win10 1. First, press the "Win+I" keys to open the settings interface, and click to enter the "System" settings. 2. Then, in the opened interface, click "About" on the left, then find and click "Advanced System Settings". 3. Then, in the pop-up window, switch to the "" option bar and click "User Configuration" below.

Angular components and their display properties: understanding non-block default values Angular components and their display properties: understanding non-block default values Mar 15, 2024 pm 04:51 PM

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.

See all articles