您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Yii --Command 任务处理_PHP教程

2024/4/7 8:06:11发布10次查看
1.配置,执行任务所需要的组件
任务配置文件:/protected/config/console.php
配置方法跟配置main文件差不多[html]
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', 
            ), 
    ), 
); 
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[html] 
0;$i++){ 
            self::echoword($i); 
            sleep(2);//休眠2秒
//跳出 
            if(i==500){ 
                break; 
            } 
        } 
    }
/** 
     * 输出hollo word 
     */ 
    public function echoword($i){ 
        echo hollo word --$i\n; 
    } 

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命令即出现提示,提示列表显示刚才写的任务文件[html] 
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 individual command help, use the following: 
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 individual command help, use the following:执行命令 yiic go 可实现任务处理
http://www.bkjia.com/phpjc/477288.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/477288.htmltecharticle1.配置,执行任务所需要的组件 任务配置文件:/protected/config/console.php 配置方法跟配置main文件差不多[html] ?php // this is the configuration for yi...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product