php Laravel “没有准备好运行的预定命令。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30700396/
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 "No scheduled commands are ready to run."
提问by
I've set up the following Laravel commands:
我已经设置了以下 Laravel 命令:
protected function schedule(Schedule $schedule) {
$schedule->command('command:daily-reset')->daily();
$schedule->command('command:monthly-reset')->monthly();
}
Then, on my server, I've set up a cron job to run once per day (at 00:00).
然后,在我的服务器上,我设置了一个每天运行一次的 cron 作业(在 00:00)。
0 0 * * * php /home/privates/public_html/staging/current/artisan schedule:run
My cron job is running successfully each night, but the logs simply say: "No scheduled commands are ready to run."
我的 cron 作业每晚都成功运行,但日志只是说:“没有准备好运行的预定命令。”
What am I doing wrong? I would expect my daily
command to run each night.
我究竟做错了什么?我希望我的daily
命令每晚运行。
Thanks!
谢谢!
采纳答案by chanafdo
Did you try running command manuallay?
您是否尝试运行命令 manuallay?
Run php artisan
and see if your commands have registered.
运行php artisan
并查看您的命令是否已注册。
If you have registered your commands you should see command:daily-reset
and command:monthly-reset
under the list of available artisan commands.
如果您已经注册了您的命令,您应该会在可用的 artisan 命令列表下方看到command:daily-reset
和command:monthly-reset
。
If you don't see them there go ahead and register your commands by adding it to commands
property available in app/Console/Kernel.php
.
如果你没有看到他们有继续前进,将它添加到您的注册命令commands
财产提供app/Console/Kernel.php
。
protected $commands = [
'App\Console\Commands\YourFirstCommand',
'App\Console\Commands\YourSecondCommand'
];
Change crontab entry to
将 crontab 条目更改为
* * * * * php /home/privates/public_html/staging/current/artisan schedule:run
* * * * * php /home/privates/public_html/staging/current/artisan schedule:run
回答by tsveti_iko
When you run
当你跑
php artisan schedule:run
in the server, where your project is stored, you could see all of your commands running with output, looking like this:
在存储您的项目的服务器中,您可以看到所有运行的命令和输出,如下所示:
"Running scheduled command: '/usr/local/bin/php' 'artisan' cache:update > '/dev/null' 2>&1 &"
but only if the current time is the exact one, for which the command is scheduled. Otherwise you are going to see this output:
但前提是当前时间是为该命令安排的确切时间。否则你会看到这个输出:
"No scheduled commands are ready to run."
For example, if you schedule the command for every five minutes and run the command in 09:07 o'clock you will see that there are no scheduled commands, but if you run it in 09:10 you will see your command running.
例如,如果您每五分钟安排一次命令并在 09:07 点运行该命令,您将看到没有安排好的命令,但如果您在 09:10 运行它,您将看到您的命令正在运行。
In this way you can just schedule your command to run every 5 min just for debugging purposes:
通过这种方式,您可以将命令安排为每 5 分钟运行一次,仅用于调试目的:
$schedule->command('command:daily-reset')->everyFiveMinutes();
then observe if there is any error while running and eventually fix it. By me the problem was that I haven't installed GuzzleHttp (shame), so the fix was just running this in the terminal:
然后观察运行时是否有任何错误并最终修复它。我的问题是我没有安装 GuzzleHttp(耻辱),所以修复只是在终端中运行它:
composer require guzzlehttp/guzzle
回答by Moses Ndeda
I realized that the problem for me was the below chained method:
我意识到我的问题是下面的链接方法:
->withoutOverlapping()
Once I removed that method, my commands started running and being found by the daemon process.
删除该方法后,我的命令开始运行并被守护进程找到。
I think there might be a bug with the method, but my project for now can take a bit overlapping so it's cool.
我认为该方法可能存在错误,但我现在的项目可能会有些重叠,因此很酷。
回答by Octavio Herrera
The Laravel scheduled commands are based in the timezone that you have configured in your app/config/app.php file (laravel 5.1):
Laravel 计划命令基于您在 app/config/app.php 文件(laravel 5.1)中配置的时区:
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'America/Bogota',
So if you create a command and register it to run as a scheduled task with:
因此,如果您创建一个命令并将其注册为作为计划任务运行:
$schedule->command('command:daily-reset')->daily();
it will run every day at 00:00 OF THE TIMEZONE SPECIFIED (in this case America/Bogota)
它将每天在指定时区的 00:00 运行(在这种情况下是美国/波哥大)
The same thing applies if you specify a time to run the task:
如果您指定运行任务的时间,则同样适用:
$schedule->command('command:daily-reset')->daily()->at('02:30');
This will run at 02:30 am in America/Bogota local time.
这将在美国/波哥大当地时间凌晨 02:30 运行。
回答by David Lartey
NB: This is not answer for this question, but a clue for anyone debugging with php artisan schedule:run
manually. Hope it saves someone a few minutes of headache.
注意:这不是这个问题的答案,而是任何php artisan schedule:run
手动调试的人的线索。希望它可以为某人节省几分钟的头痛。
Check if the scheduled task can run immediately. You can use the exec
method for that.
检查计划任务是否可以立即运行。您可以使用该exec
方法。
<?php
...
protected function schedule (Schedule $schedule) {
$schedule -> exec("php artisan your:command");
}
The reason for this is that, you might be scheduling the task to run at a certain time and if that time isn't due yet, it will output: "No scheduled commands are ready to run."
这样做的原因是,您可能将任务安排在某个时间运行,如果该时间尚未到期,它将输出:“没有准备好运行的计划命令。”
回答by cartbeforehorse
The full answer to this question is not listed above as far as I can see. Let's assume that our schedule is as follows:
据我所知,上面没有列出这个问题的完整答案。假设我们的日程安排如下:
protected function schedule(Schedule $schedule)
{
$schedule
-> command('cbh:dummyCommand')
-> everyFiveMinutes()
-> appendOutputTo ('/my/logs/laravel_output.log');
}
What I've discovered is that this code doesn't set your job to run every 5 minutes. Nor does it prevent the command running again if it was run less than 5-minutes ago.
我发现此代码不会将您的工作设置为每 5 分钟运行一次。如果命令在不到 5 分钟前运行,它也不会阻止命令再次运行。
A better way to think about it is that this code sets the named command "to be runnable every time the minute-figure of the current time is 0
or 5
". In other words, if I run the command-line argument: php artisan schedule:run
at 11:04
, then the response is:
更好的思考方式是,这段代码将命名命令设置为“每次当前时间的分钟数为0
or时都可运行5
”。换句话说,如果我运行命令行参数:php artisan schedule:run
at 11:04
,那么响应是:
# No scheduled commands are ready to run.
But if I run the same command at 11:00
or 11:05
, then we get:
但是如果我在11:00
or处运行相同的命令11:05
,那么我们得到:
# Running scheduled command: php artisan cbh:dummyCommand >> /my/logs/laravel_output.log 2>&1
And I end up with output in my log-file.
我最终在我的日志文件中输出。
I discovered the above when my everyFiveMinutes()
schedule was creating a log in my file every 10 minutes based on the fact that my task-scheduler was running every 2 minutes.
everyFiveMinutes()
根据我的任务调度程序每 2 分钟运行一次的事实,我在我的日程安排每 10 分钟在我的文件中创建一个日志时发现了上述情况。
However, this doesn't quite address your issue, given that the daily()
schedule (0 0 * * *
) aligns with your cron-job schedule. The only thing I can imagine is that there is some kind of misalignment with your time-zones as suggested by @Octavio Herrera. But that's difficult to say without knowing a bit more about your environment.
但是,这并不能完全解决您的问题,因为daily()
计划 ( 0 0 * * *
) 与您的 cron-job 计划一致。我唯一能想象的是,正如@Octavio Herrera 所建议的那样,您的时区存在某种错位。但是,如果不了解更多有关您的环境的信息,就很难说出来。
回答by Sebastien
I had the same problem. Every command was correctly registeredbut I always received the “No scheduled commands are ready to run.”message. The problem was that the website was in "maintenance mode"(php artisan downcommand) while we were doing updates and tests.
我有同样的问题。每个命令都已正确注册,但我总是收到“没有准备好运行的计划命令”。信息。问题是在我们进行更新和测试时,网站处于“维护模式”(php artisan down命令)。
回答by Nguyen Sy Thanh Son
I think that my blog will help you answer your question. Please see the below or link: Laravel CrontabIn many projects, you need use crontab (cron jobs) to execute some tasks as sending email or delete waste record in DB. With Laravel Project, you can do this easier.
我认为我的博客将帮助您回答您的问题。请参阅以下或链接:Laravel Crontab在许多项目中,您需要使用 crontab(cron 作业)来执行一些任务,例如发送电子邮件或删除 DB 中的垃圾记录。使用 Laravel 项目,您可以更轻松地做到这一点。
Be strong enough to let go and patient enough to wait for what you deserve Be strong enough to let go and patient enough to wait for what you deserve
足够坚强去放手 足够耐心等待你应得的 足够坚强去放手 足够耐心等待你应得的
Create a command in Laravel 4:
在 Laravel 4 中创建一个命令:
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class FirstCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'user:active';
/**
* 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 fire()
{
echo "User Actived";
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
Next step, you need to register the command with Laravel CLI. So easy, you open app/start/artisan.php file, and add one line as below:
下一步,您需要使用 Laravel CLI 注册命令。很简单,你打开 app/start/artisan.php 文件,添加如下一行:
Artisan::add(new FirstCommand);
You are done creating Laravel Command. To test, you could use command below:
你已经完成了 Laravel 命令的创建。要测试,您可以使用以下命令:
$ php artisan user:active
User Active The output above mean you successfully register a command.
User Active 上面的输出意味着您成功注册了一个命令。
Finally, put your command into the crontab:
最后,将您的命令放入 crontab:
crontab -e
Add line (run command every 2 minutes):
添加行(每 2 分钟运行一次命令):
*/2 * * * * php path_to_laravel_project/artisan user:active
That's all. Thank you for talking time to read this.
就这样。感谢您抽出时间阅读本文。
回答by Damilola Olowookere
Since I still ran into this issue 4 years later (2019) and a different workaround worked for me, I think it is worth hinting the simple step that solved for me, which is: Use a shorter interval first.
由于我在 4 年后(2019 年)仍然遇到这个问题,并且不同的解决方法对我有用,我认为值得暗示为我解决的简单步骤,即:首先使用较短的间隔。
That seems to just wake it up to handle longer intervals in some ways. I had everyFiveMinutes()
and for almost 2 hours it was getting the No scheduled commands are ready to run
response. I simply changed it to everyMinute()
and it started running correctly. I watched it consistently for like 10 minutes or so, then changed it back to everyFiveMinutes()
and it all went smoothly.
这似乎只是唤醒它以在某些方面处理更长的间隔。我有,everyFiveMinutes()
并且在将近 2 小时内得到了No scheduled commands are ready to run
回应。我只是将其更改为everyMinute()
并开始正常运行。我持续看了大约 10 分钟,然后将其改回,everyFiveMinutes()
一切都很顺利。
回答by voidstate
On Windows, I fixed this issue by setting the Scheduled Task to run every minute(even though I only wanted to trigger a command once per day), otherwise I always got the No scheduled commands are ready to run.
message.
在 Windows 上,我通过将计划任务设置为每分钟运行一次来解决这个问题(即使我只想每天触发一次命令),否则我总是收到No scheduled commands are ready to run.
消息。