我在使用php artisan cron时遇到一些问题。
当前,这些任务位于App \ Console \ Commands \ task1.php中而cron在App \ Console \ Kernel.php]中定义
问题是:任务没有启动。
所以我尝试使用命令行创建一个新任务:php path/to/artisan make:command task2
并且将创建一个文件,但是在App \ Commands中,而不是App \ Console \ Commands中。
并且当尝试使用artisan list
列出现有的cron任务时,我只会得到:vendor:publish Publish any publishable assets from vendor packages
我应该将命令放在哪里?内核文件应该在哪里?
当前,Kernel.php是:
<?php namespace App\Console; use App\Commands\Task2; use App\Console\Commands\Task1; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { protected $commands = [ Task1::class, Task2::class, ]; protected function schedule(Schedule $schedule) { $schedule->command('task1')->daily(); $schedule->command(Task2::class)->daily(); } }
Task1,使用命令行在App \ Commands文件夹中创建的任务:
<?php namespace App\Commands; use Illuminate\Console\Command; use Illuminate\Contracts\Bus\SelfHandling; class Task1 extends Command implements SelfHandling { protected $name = 'task1'; protected $description = 'Task1 test '; public function handle() {} }
Task2,在App \ Console \ Commands文件夹中:
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
class Task2 extends Command {
protected $name = 'task2';
protected $description = 'task 2 test';
public function handle()
{}
}
我在使用php artisan cron时遇到一些问题。当前,任务在App \ Console \ Commands \ task1.php中,而cron在App \ Console \ Kernel.php中定义。问题是:任务未启动。所以...
您需要$signature
而不是$name
在Kernel.php中更改