http://happymc.iteye.com/blog/2149924
1.cron.php
<?php
// change the following paths if necessary
$yiic=dirname(__FILE__).'/../../framework/yiic.php';
$config = dirname ( __FILE__ ) . '/../config/console.php';
require_once ($yiic);
2.console.php
<?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',
'import' => array (
'application.models.*',
'application.components.*',
),
'components' => array (
// Main DB connection
'db'=>array(
'connectionString' => 'mysql:host=39.107.44.226:3306;dbname=ddj_app',
'schemaCachingDuration' => 3600,
'emulatePrepare' => true,
'enableParamLogging' => true,
'username' => 'root',
'password' => 'DB@KPL$88!2018',
'charset' => 'utf8',
'tablePrefix' => 'fst_',
),
'log' => array (
'class' => 'CLogRouter',
'routes' => array (
array (
'class' => 'CFileLogRoute',
'levels' => 'error, warning'
)
)
)
)
);
3.TestCommand.php
<?php
/**
* 自动化执行 命令行模式
*/
class TestCommand extends CConsoleCommand
{
public function run($args)
{
$data = array('username' => 'ezreal', 'password' => date("Y-m-d H:i:s"));
try {
return Yii::app()->db->createCommand()->insert('gzc_user', $data);
} catch (Exception $ex) {
return null;
}
}
public function test2()
{
echo 'this is a test';
}
}
4. php crons.php test test2 运行