I've set up the following Laravel commands:
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).
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."
What am I doing wrong? I would expect my daily
command to run each night.
Thanks!
I think that my blog will help you answer your question. Please see the below or link: Laravel Crontab In 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.
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:
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:
You are done creating Laravel Command. To test, you could use command below:
User Active The output above mean you successfully register a command.
Finally, put your command into the crontab:
Add line (run command every 2 minutes):
That’s all. Thank you for talking time to read this.
When you run
in the server, where your project is stored, you could see all of your commands running with output, looking like this:
but only if the current time is the exact one, for which the command is scheduled. Otherwise you are going to see this output:
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.
In this way you can just schedule your command to run every 5 min just for debugging purposes:
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:
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.Check if the scheduled task can run immediately. You can use the
exec
method for that.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."
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:
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.
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
or5
". In other words, if I run the command-line argument:php artisan schedule:run
at11:04
, then the response is:But if I run the same command at
11:00
or11:05
, then we get: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.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.I realized that the problem form me was the
chained method. 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.
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.