Laravel 任务调度设置为每分钟运行一次,但只运行一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37265929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Task Scheduling set to run every minute but it run only once
提问by alextre
I am using Laravel Task Scheduling. I defined a custom command
and set it to run every minute like:
我正在使用 Laravel 任务调度。我定义了一个自定义command
并将其设置为每分钟运行一次,例如:
$schedule->command('dailyk')->everyMinute();
Then I used the following command to run the task:
然后我使用以下命令来运行任务:
php /var/www/stockhit/artisan schedule:run 1>> /dev/null 2>&1
I used log to check that my custom command continued to run. However, it is not run every minute. Instead, it just ran once.
我使用 log 来检查我的自定义命令是否继续运行。但是,它不是每分钟运行一次。相反,它只运行了一次。
How can I make it run every minute, instead of just one time?
我怎样才能让它每分钟运行一次,而不是一次?
采纳答案by Eli Algranti
See Task Scheduling:
参见任务调度:
Here is the only Cron entry you need to add to your server:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled tasks and runs the tasks that are due.
这是您需要添加到服务器的唯一 Cron 条目:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
这个 Cron 每分钟都会调用 Laravel 命令调度程序。然后,Laravel 评估您的计划任务并运行到期的任务。
Laravel's task scheduler does not stay in memory, it needs to be run every minute. It will then check which tasks need to be run in that minute and run them. When you run the task scheduler using PHP it just runs once, it needs cron to run it every minute.
Laravel 的任务调度器不会留在内存中,它需要每分钟运行一次。然后它将检查在那一分钟内需要运行哪些任务并运行它们。当您使用 PHP 运行任务调度程序时,它只运行一次,它需要 cron 每分钟运行一次。
回答by jclyons52
you need to add a cron job. On ubuntu use the command
您需要添加一个 cron 作业。在 ubuntu 上使用命令
crontab -e
to open your cron job file, then add
打开您的 cron 作业文件,然后添加
* * * * * php /var/www/stockhit/artisan schedule:run 1>> /dev/null 2>&1