Reputation: 165
I have a task scheduled to run an artisan command, and whenever i run artisan command it is executing every time irrespective of time i have given to the cron job.
Here is the console i'm using
class CronJobConsole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sms:note';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//executing function;
}
$this->info('Remainder SMS send successfully !!');
}
}
and this is my console/kernel.php file
class Kernel extends ConsoleKernel
{
protected $commands = [
\App\Console\Commands\Inspire::class,
\App\Console\Commands\FileEntryData::class,
\App\Console\Commands\CronJobConsole::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('sms:note')->dailyAt('19:00')->sendOutputTo('cronjob-result.php');
}
}
when i run the php artisan sms:note it is executing every time. I want it to execute on particular time that i have gven.
Please help me out.
Upvotes: 1
Views: 1313
Reputation: 1320
This problem, as you specify it, is just artisan's normal behaviour.
You have scheduled the command, so it will be executed on the specified time driven by Laravels internal scheduler (read below cronjob). But you can also manually execute the command, by entering it in CLI.
Note: executing your command manually has nothing to do with artisan's scheduler. The scheduler only executes this command whenever you see fit.
So the command you are looking for is:
php artisan schedule:run
This commands loops through the registered commands on the specified time, so it will only run your command when the time is ready.
To make sure Laravel executes your command when it's time, create a cronjob (on your server) to run the php artisan schedule:run
command every minute, Laravel takes care of the rest.
From the docs (insert in crontab):
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Goodluck!
Upvotes: 3