How to implement Command task processing through Yii

不言
Release: 2023-04-01 09:06:02
Original
1591 people have browsed it

This article mainly introduces the method of Yii to implement Command task processing, and analyzes the steps and related techniques of configuring, loading and using Command task processing in Yii in the form of examples. Friends in need can refer to this article

The example describes how Yii implements Command task processing. Share it with everyone for your reference, the details are as follows:

1. Configuration, the components required to perform the task

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

The configuration method is similar to configuring the main file

dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=>'My Console Application', // application components // 自动载入的模型和组件类 'import'=>array( 'application.models.*',//载入"application/models/"文件夹下的所有模型类 'application.components.*',//载入"application/components/"文件夹下的所有应用组件类 'application.extensions.*',//载入"application/extensions/"文件夹下的所有应用组件类 ), 'components'=>array( // uncomment the following to use a MySQL database 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=dbname',//连接mysql数据库 'emulatePrepare' => true, 'username' => 'root',//MySQL数据库用户名 'password' => '123456',//MySQL数据库用户密码 'charset' => 'utf8',//MySQL数据库编码 'tablePrefix' => 'zd_', //MySQL数据库表前缀 'enableProfiling'=>true, 'enableParamLogging'=>true, ), //加载Email组件 'mailer' => array( 'class' => 'application.extensions.mailer.EMailer', ), ), );
Copy after login

2. The task file

is placed in The task file naming method that inherits the CConsoleCommand base class in the /protected/commands/ file directory is Task name Command

For example, GoCommand.php

0;$i++){ self::echoWord($i); sleep(2);//休眠2秒 //跳出 if(i==500){ break; } } } /** * 输出hollo word */ public function echoWord($i){ echo "hollo word --$i\n"; } }
Copy after login

3. Execute the task

Open the command line tool, enter the /protected directory of the project and enter the yiic command. A prompt will appear. The prompt list displays the task file just written

E:\project\app\protected>yiic Yii command runner (based on Yii v1.1.12) Usage: E:\zeee\zyd\protected\yiic.php  [parameters...] The following commands are available: - go - mailqueue - message - migrate - shell - webapp To see inpidual command help, use the following:
Copy after login

Execute the command yiic go to achieve task processing

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to PHP Chinese website!

Related recommendations:

About common methods of CDBCriteria in Yii

How to solve the problem of session cross-domain coexistence under Yii2

The above is the detailed content of How to implement Command task processing through Yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!