Artisan Schedule运行不运行所有命令

时间:2017-11-01 17:28:54

标签: php laravel artisan laravel-scheduler

我试图让Laravel Scheduler运行一些命令,但是当我运行php artisan schedule:run时,它只会运行kernal.php文件中的一个命令。

我的Kernal.php文件如下:

protected $commands = [
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('a:import')->everyMinute();
    $schedule->command('b:import')->everyFiveMinutes();
}

/**
 * Register the Closure based commands for the application.
 *
 * @return void
 */
protected function commands()
{
    require base_path('routes/console.php');
}

我的console.php文件包含以下代码:

Artisan::command('a:import', function(a\ImportController $runner) {
    $runner->init();
});

Artisan::command('b:import', function(b\ImportController 
$runner) {
    $runner->beginImport();
});

当我运行php artisan schedule:run我得到以下结果:

D:\development\v2> php artisan schedule:run

 ´╗┐Running scheduled command: "C:\Program Files\PHP\v7.0\php.exe" "artisan" a:import > "NUL" 2>&1

任何帮助确定我错过的内容或我需要做的任何事情都将不胜感激。

4 个答案:

答案 0 :(得分:0)

输出可能有点误导,但实际上是有效的。您将a:import设置为每分钟运行一次b:import每5分钟运行一次,以便运行时:

php artisan schedule:运行

您会看到a:import命令的运行频率是b:import

的5倍

答案 1 :(得分:0)

你设置了一个cron,当然它不会运行......

答案 2 :(得分:0)

您是否在crontab中添加了schedule命令?

答案 3 :(得分:0)

您必须在 $ commands 数组中注册自定义命令:

protected $commands = [
    Commands\A::class,
    Commands\B::class
];