我正在尝试让Laravel Scheduler运行几个命令,但是当我运行php artisan schedule:run
时,它只会运行kernal.php文件中的一个命令。
我的Kernel.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
任何帮助,以确定我错过了什么或我需要做的任何其他事情将不胜感激。
输出可能有点误导,但实际上是有效的。你将a:import
设置为每分钟运行一次,b:import
to每5分钟运行一次,这样当你运行时:
php工匠时间表:运行
你会看到a:import
命令比b:import
经常运行5次
你有没有设置一个cron,当然它不会运行...
您是否在crontab中添加了schedule命令?
您必须在$ commands数组中注册自定义命令:
protected $commands = [
Commands\A::class,
Commands\B::class
];