1.配置,执行任务所需要的组件

任务配置文件:/protected/config/console.php 
配置方法跟配置main文件差不多

<?php

// 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 // 自动载入的模型和组件类
'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',
),
),
);

2.任务文件

放在 /protected/commands/ 文件目录下继承 CConsoleCommand 基类的为任务文件 命名方法为   任务名称+Command
例如 GoCommand.php

<?php

/**
* 自动运行文件
*/
class GoCommand extends CConsoleCommand
{ /**
* 死循环输出
*/
public function run(){ for($i=1;$i>0;$i++){
self::echoWord($i);
sleep(2);//休眠2秒 //跳出
if(i==500){
break;
}
}
} /**
* 输出hollo word
*/
public function echoWord($i){
echo "hollo word --$i\n";
}
}

3.执行任务

打开命令行工具,进入项目的/protected 目录下 输入yiic命令即出现提示,提示列表显示刚才写的任务文件

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

执行命令 yiic go 可实现任务处理

Yii --Command 任务处理的更多相关文章

  1. yii2 ./yii command : No such file or directory

    git clone下来的yii2后台项目,由于需要执行 ./yii migrate命令.执行之后,提示 No such file or directory 我从同样为yii2 basic的./yii ...

  2. Yii 初识

    接管一个Yii的系统,因为没有文档,所以非常上火. 01 查版本 Yii::getVersion(); 02 生成webapp Yii 是支持通过命令行生成webapp的.其中, yiic.bat是W ...

  3. yii console

    Here is a step by step to show how to run command in the server with yii framework. 1. Create the we ...

  4. yii int

    @echo off rem ------------------------------------------------------------- rem Yii command line ini ...

  5. yii框架通过控制台命令创建定时任务

    假设Yii项目路径为 /home/apps 1. 创建文件 /home/apps/web/protected/commands/console.php $yii = '/home/apps/frame ...

  6. YII Install 安装

    Download     Yii is an open source project released under the terms of the BSD License. This means t ...

  7. yii 核心类classes.php详解(持续更新中...)

    classes.php在yii运行的时候将被自动加载,位于yii2文件夹底下. <?php /** * Yii core class map. * * This file is automati ...

  8. 拓展Yii Framework(易框架)

    1.拓展yii 此文针对Yii1.1.15而写,请注意甄别你的Yii Framework 版本. 拓展yii是开发期间常见的代码处理方式.例如,你写一个新的controller(业务控制器),你通过继 ...

  9. Yii 框架学习--02 进阶

    应用结构 入口文件 文件位置: web/index.php <?php //开启debug,应用会保留更多日志信息,如果抛出异常,会显示详细的错误调用堆栈 defined('YII_DEBUG' ...

随机推荐

  1. (Problem 16)Power digit sum

    215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...

  2. search_word

    一个小程序,用asc码输出自己的名字.要求是,a~z两路输入,输出了一个完整的拼音之后还需要输出一个空格.—— 信息硬件过滤的雏形. module search_word ( clock , rese ...

  3. 基于visual Studio2013解决算法导论之050强连通分支

     题目 强连通分支 解决代码及点评 // 强连通分支.cpp : 定义控制台应用程序的入口点. // #include<iostream> #define MAX 100 using ...

  4. 测试DOM0级事件和DOM2级事件的堆叠

    1. 问题 如果大家看过北风网CJ讲师的Javascript视频教程,就可以看到其封装了一个很强的事件添加和删除函数,如下所示 function addEvent(obj, evtype, fn) { ...

  5. NDK如何调试系统核心动态库(无系统源码的情况)

    版权归薛定諤耗子所有,转载请表明出处. 1,有源码,需要导入符号表 2,没有源码,如何调试 1)运行ndk-gdb:../../ndk-gdb --verbose --launch=com.examp ...

  6. arm汇编:ldr,str,ldm,stm,伪指令ldr

    ldr,str,ldm,stm的命名规律: 这几个指令命名看起来不易记住,现在找找规律. 指令 样本 效果 归纳名称解释 ldr Rd,addressing ldr r1,[r0] addressin ...

  7. DeDeCMS中如何实现下拉菜单

    在5.7版本,已经有比较简单的方法实现下拉菜单,我们可以用它已有方法,也可以用我写的第二种方法来实现 1. 在需要下拉菜单的地方加入以下代码 <div id="navMenu" ...

  8. ant—学习记录一

    <?xml version="1.0"?> <project name="helloWorld"> <target name=&q ...

  9. HDOJ4006 The kth great number 【串的更改和维护】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  10. Qt学习之路(49): 通用算法

    今天开始的部分是关于Qt提供的一些通用算法.这部分内容来自C++ GUI Programming with Qt 4, 2nd Edition.   <QtAlgorithms>提供了一系 ...