Yii:cronjobタイミングタスクの作成
1.環境構成の追加
protected/config/console.php
2.タイミングタスク実行モジュールの追加
protected/commands/crons.php
3.特定のタイミングタスクを追加
タイミングタスクは通常、CConsoleCommandクラスから派生するコマンドラインプログラムです.たとえば、
protected/commands/TestCommand.php
4.cronjobの作成
30 0 * * * www php/path/to/crons.php Test >>/path/to/logs/test.log
5.入力パラメータをタイミングタスクのrun($params)に与える
30 0 * * * www php/path/to/crons.php Test param1 param2 ...
by iefreer
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.タイミングタスク実行モジュールの追加
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.特定のタイミングタスクを追加
タイミングタスクは通常、CConsoleCommandクラスから派生するコマンドラインプログラムです.たとえば、
protected/commands/TestCommand.php
class TestCommand extends CConsoleCommand
{
public function run($args) {
//todo
}
}
4.cronjobの作成
30 0 * * * www php/path/to/crons.php Test >>/path/to/logs/test.log
5.入力パラメータをタイミングタスクのrun($params)に与える
30 0 * * * www php/path/to/crons.php Test param1 param2 ...
by iefreer