I have setup the follow Laravel Cronjob command:
protected function schedule(Schedule $schedule)
{
$schedule->command('DataDownloader:downloaddata')->dailyAt('19:34');
}
This saves some data from an API into a mySQL database. The command is listed under php artisan and I am able to run it using php artisan DataDownloader:downloaddata.
I have added the Cron entry to my crontab as per Laravel documentation:
* * * * * php /var/www/html/myprojectname/artisan schedule:run >> /dev/null 2>&1
When I run php artisan schedule:run it tells me 'No scheduled commands are ready to run'. I don't really know if this suggests if my Cronjob does not work at all or it is just broken.
Am I missing something or did I do something wrong that prevents the Cron from running?
My server is running Ubuntu with NGINX.
schedule:run command fires other commands that are ready to run at the time of its execution. So it means that in that exact time you ran it, no command was to be started.
However, you have defined cron that runs schedule:run every minute, thus when 19:34 comes, your command will be executed.
Related
My queue is working perfectly, when i run the following command php artisan queue:work
I’m using database as a QUEUE_DRIVER. On the server i don’t run the above command every-time.
for eg:
In schedule we have to run the command php artisan schedule:work. In this case on server we register this in cronetab like this:
* * * * * php /path/of/the/project/artisan schedule:run 1>> /dev/null 2>&1
Then we don’t have to run schedule work command again and again.
Is something also for queue. So we don’t have to run php artisan queue:work again and again. Also i don’t want to change the driver.
Laravel docs:
cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. When
the schedule:run command is executed, Laravel will evaluate your
scheduled tasks and runs the tasks that are due.
I run these codes below in app\Console\Kernel.php:
$schedule->job(new \App\Jobs\done)->everyMinute();
$schedule->command('done:done')->everyMinute();
but none of them worked! so I run the command php artisan schedule:run but it runs only once and each time I want to make it trigger the job/command I should run that command so I tried to use the command above in Laravel docs. However again it didn't work every minute. So I tried to create a task in Task Scheduler and run it every 5 minutes(because it didn't have less than 5) now it's working but the usage of ->everyMinute() is redundant because the schedule of Laravel only runs but the main job that is done is by Windows Task Scheduler. So how can I fix it in order not to use cron job nor windows task scheduler?
Thanks
Just so you can close the question.
As I said in the comments / chat
You should be able to set every minutes on Windows Task Scheduler:
http://somoit.net/windows/scheduled-task-every-minute
You can also use php artisan done:done in your Windows Task Schedule and not use the Laravel Kernel at all.
For the fact that everyMinute() is ignored when you run the job manually is because Laravel know that a cron can't be executed more than once a minute. So it doesn't keep a trace for a job set to everyMinute(). This mean, every time you run the command php artisan schedule:run it will run the job.
And has #kyslik mentioned in the chat : The scheduler is well covered in the official documentation: https://laravel.com/docs/5.7/scheduling#introduction
I have this in my Kernal.php
$schedule->call(function () {
DB::table('news')->delete();
})->everyMinute();
when i do
php artisan schedule:run
it works fine.
But when i use cpanel and write in cron job
php /home/allnewsnepal/public_html/artisan schedule:run >> /dev/null 2>&1
the code doesnt run automatically.I dont have access to shell of cpanel.
For cron's in cPanel, you can look in this post:
Run a PHP file in a cron job using CPanel
The things that you should pay attention to are:
Global path of your PHP (e.g. /usr/bin/php)
Global path of your Laravel (e.g. /var/www/html/LaravelProjectName)
In order to start a cron job on Linux based systems, you must specify the user for that cron, let's say the user is root, so the cron job would look like this:
root php /home/allnewsnepal/public_html/artisan schedule:run >> /dev/null 2>&1
Of course with * prefixes depending on your cron schedule
Thanx for the help .
I got my problem solved by doing
php-cli -q /home/allnewsnepal/public_html/artisan schedule:run
I've a Laravel 5.3 on an Azure instance, everything is working cool there except my task scheduler, I'm tryin to run an Artisan command automatically every midnight, when I run the same command from the CLI it works well.
I tried to use this command as in the Laravel Doc:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
it worked out just once, then the process ends and not repeated for the 2nd round.
What should I do to let the scheduler run the task everyday?
P.S: here's my code how do I run the command through the kernel:
protected function schedule(Schedule $schedule)
{
$schedule->command('rentalRates:run')->daily();
}
Since your command is scheduled to run daily, it will only run once per day if you use schedule:run.
If you wish to run the particular command manually (and more than once in a day), you can use the following from command line:
php /path-to-your-project/artisan rentalRates:run
i have installed a Laravel package for dumping my database.
The plugin runs find, but i want to run it every day as a cronjob.
Here is the inserted command in Kernel.php:
$schedule->command('db:backup')->dailyAt('01:50');
Unfortunately it hasn't done anything.
Is it possible to run an artisan command direct in the Kernel.php without a Command class ?
Have you made sure to add the task to your system crontab? Typically located at /etc/crontab
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
From https://laravel.com/docs/5.3/scheduling
PHP has no way of executing itself, so you need to set up a system task to call artisan every second, so laravel can evaluate the cron expressions and run them as needed.