39142 2016-10-18 20:11:00 2686次浏览 0条回复 0 0 0

1.问题:需要利用cron定时执行console任务,在本地测试环境中执行正常,但在godaddy的web空间执行则出现错误,看起来是路由的问题,还请帮忙看一下,多谢。

2.入口脚本Webroot/yii

#!/usr/bin/env php
<?php
/**
 * Yii console bootstrap file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

defined('YII_DEBUG') or define('YII_DEBUG', true);

// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/config/console.php');

$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

3.配置文件Webroot/config/console.php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');

return [
    'id' => 'basic-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log', 'gii'],
    'controllerNamespace' => 'app\commands',
    'modules' => [
        'gii' => 'yii\gii\Module',
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'api' => [
            'class' => 'app\components\Api'

        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
    ],
    'params' => $params,
];

4.Webroot/commands/CronController.php

namespace app\commands;
 
use yii\console\Controller;
use Yii;
use yii\helpers\Url;
use yii\db\Query;

class CronController extends Controller
{
   public static function actionCron()
    {
	//code	
    }
}

5.本地测试环境执行正常

php Webroot/yii cron/cron

6.godaddy的web空间执行php Webroot/yii cron/cron错误结果

This is Yii version 2.0.5.

The following commands are available:

- asset                        Allows you to combine and compress your JavaScript and CSS files.
    asset/compress (default)   Combines and compresses the asset files according to the given configuration.
    asset/template             Creates template of configuration file for [[actionCompress]].

- cache                        Allows you to flush cache.
    cache/flush                Flushes given cache components.
    cache/flush-all            Flushes all caches registered in the system.
    cache/flush-schema         Clears DB schema cache for a given connection component.
    cache/index (default)      Lists the caches that can be flushed.

- cron                         
    cron/index (default)

- fixture                      Manages fixture data loading and unloading.
    fixture/load (default)     Loads the specified fixture data.
    fixture/unload             Unloads the specified fixtures.

- gii                          This is the command line version of Gii - a code generator.
    gii/controller             Controller Generator
    gii/crud                   CRUD Generator
    gii/extension              Extension Generator
    gii/form                   Form Generator
    gii/index (default)
    gii/model                  Model Generator
    gii/module                 Module Generator

- hello                        This command echoes the first argument that you have entered.
    hello/index (default)      This command echoes what you have entered as the message.

- help                         Provides help information about console commands.
    help/index (default)       Displays available commands or the detailed information

- message                      Extracts messages to be translated from source files.
    message/config             Creates a configuration file for the "extract" command.
    message/extract (default)  Extracts messages to be translated from source code.

- migrate                      Manages application migrations.
    migrate/create             Creates a new migration.
    migrate/down               Downgrades the application by reverting old migrations.
    migrate/history            Displays the migration history.
    migrate/mark               Modifies the migration history to the specified version.
    migrate/new                Displays the un-applied new migrations.
    migrate/redo               Redoes the last few migrations.
    migrate/to                 Upgrades or downgrades till the specified version.
    migrate/up (default)       Upgrades the application by applying new migrations.


To see the help of each command, enter:

  yii help <command-name>

X-Powered-By: PHP/5.6.25
Content-type: text/html; charset=UTF-8
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册