When your command is made available to your application, you can use Laravel to schedule it to run at pre-defined intervals, just like you would a CRON.
In The app/Console/Kernel.php file you will find a schedule
method that you can use to schedule your task.
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\Inspire::class,
Commands\MyTaskName::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('my:task')->everyMinute();
// $schedule->command('my:task')->everyFiveMinutes();
// $schedule->command('my:task')->daily();
// $schedule->command('my:task')->monthly();
// $schedule->command('my:task')->sundays();
}
}
Assuming your task's $signature
is my:task
you can schedule it as shown above, using the Schedule $schedule
object. Laravel provides loads of different ways to schedule your command, as shown in the commented out lines above.