问题描述
我如何每分钟运行我的计划任务?当我运行命令php artisan schedule:run
时,控制台会显示没有计划的命令准备运行.".我应该如何正确设置我的任务?例如,如果我使用独奏命令php artisan command:send_info_email_before_event
可以工作,但是在开发应用程序时我想用schedule:run
来做.
How i can run my Schedule task every minute? When i run command php artisan schedule:run
, console get "No scheduled commands are ready to run.". How i should set my Tasks properly? For example if I use solo command php artisan command:send_info_email_before_event
it works, but i want do it with schedule:run
when i develop app.
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('command:send_info_email_before_event')
->everyMinute();
}
推荐答案
您应该通过 cron作业进行设置,使其每分钟运行一次.任务计划不能手动运行.
You should be setting this up via cron job to run every minute. Task scheduling is not intended to be run manually.
在终端运行中:
crontab -e
然后添加:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
保存后,它将每分钟运行一次应用程序计划程序(无需运行php artisan schedule:run
.
Once saved, this will then run the application scheduler every minute (without you needing to run php artisan schedule:run
.
这篇关于如何在Laravel中每分钟运行计划任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!