欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Yii框架創(chuàng)建cronjob定時(shí)任務(wù)的方法分析

 更新時(shí)間:2017年05月23日 11:20:06   作者:陳小峰_iefreer  
這篇文章主要介紹了Yii框架創(chuàng)建cronjob定時(shí)任務(wù)的方法,結(jié)合具體實(shí)例形式分析了Yii定時(shí)任務(wù)相關(guān)配置、實(shí)現(xiàn)步驟與注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Yii框架創(chuàng)建cronjob定時(shí)任務(wù)的方法。分享給大家供大家參考,具體如下:

1. 添加環(huán)境配置

protected/config/console.php

<?php
require_once('env.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'=>'CMS Console',
  // application components
  'components'=>array(
    //Main DB connection
    'db'=>array(
      'connectionString'=>DB_CONNECTION,
      'username'=>DB_USER,
      'password'=>DB_PWD,
      'enableParamLogging'=>true,
    ),
    'log'=>array(
      'class'=>'CLogRouter',
      'routes'=>array(
        array(
          'class'=>'CFileLogRoute',
          'levels'=>'error, warning',
        ),
      ),
    ),
  ),
);

2. 添加定時(shí)任務(wù)執(zhí)行模塊

protected/commands/crons.php

<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once('/../framework/yii.php');
// we'll use a separate config file
$configFile='/config/console.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();

3. 添加具體的定時(shí)任務(wù)

定時(shí)任務(wù)通常是一個(gè)命令行程序,從CConsoleCommand類派生,比如
protected/commands/TestCommand.php

class TestCommand extends CConsoleCommand
{
  public function run($args) {
    //todo
  }
}

4. 創(chuàng)建cronjob

30 0 * * * www php /path/to/crons.php Test >>/path/to/logs/test.log

5. 傳入?yún)?shù)給定時(shí)任務(wù)中的run($params)

30 0 * * * www php /path/to/crons.php Test param1 param2 ...

更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論