Laravel scheduler is not running automatically - laravel

I have made a scheduler. When I call it with php artisan userRanking it works.
This is the code in Kernel.php:
protected $commands = [
\App\Console\Commands\UserRanking::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('userRanking')
->everyMinute();
}
How do I dispatch it so that it runs automatically?

You have to set up a single cron job that calls the schedule runner every minute:
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Read Laravel's Scheduler docs for more info.

Related

Laravel Schedule Only Exceute Command on first Run

I create a schedule to send email everyday, but for testing if it works i make it run every minute.
here is my kernel.php
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\SendExpiredReminder::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('reminder:send')
->everyMinute();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
it run every minute but reminder:send only called first time i run the schedule with php /var/www/html/artisan schedule:run >> /dev/null 2>&1
when i run php /var/www/html/artisan schedule:list it show that next due is next minute indicated the scheduler is running. What is going wrong?
your crontab should be to your laravel project folder, not www folder
* * * * * cd /var/www/html/artisan && php artisan schedule:run >> /dev/null 2>&1
note the project folder

Automatic backup not working in Laravel with Spatie

I'm trying to run backup using cron, i'm using spatie-laravel-backup it is working when i run it manually but when i run it using cron using this path on server:
/home/user/public_html && php artisan backup:run >> /home/user/logs 2>&1
and i'm getting this
/bin/bash: /home/user/public_html: Is a directory"
kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily()->at('10:00');
}
run scheduler from cron
https://laravel.com/docs/8.x/scheduling#running-the-scheduler
* * * * * cd /home/user/public_html && php artisan schedule:run >> /dev/null 2>&1
then
you can use
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily()->at('10:00');
}

Cron job issue(Task Schedule) in Laravel

Same problem schedule cron job,
my kernal.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Log;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
// \App\Console\Commands\SecondTable::class,
];
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
//->hourly();
$schedule->call('App\Http\Controllers\Sale\SaleController#sync')->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
manually running a command-> php artisan schedule:run is working good!
but, cronjob run server is not working correctly,
my cron job code,
* * * * * php /laravel project folder/artisan schedule:run >> /dev/null 2>&1
is not working.
Check your cronjob code, it could be something like this:
* * * * * cd path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
It means: every seconds (* * * * *), go to my project folder (cd path-to-your-project), then execute the command (php artisan schedule:run).
The meaning of the last part of the cronjob is explained here: What is /dev/null 2>&1?

Laravel schedule:run does not work

I am trying Laravel schedule command to run some background process for sending mails and fetching emails. When I run these commands individually using artisan they all run, but when I try to run shcedule:run command to run these commands
it shows "No scheduled commands are ready to run."
I've tried to look for an answer but nothing worked. So I tried to rectify the problem by running simple command and check the output.
Below is my kernal.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\Inspire::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
dd($schedule);
}
}
when I run schedule:run it shows this output.
Bhanu-Slathias-MacBook-Pro:Faveo-Helpdesk-Pro-bhanu-fork vijaysebastian$ php artisan schedule:run
Illuminate\Console\Scheduling\Schedule {#54
#events: array:1 [
0 => Illuminate\Console\Scheduling\Event {#1663
+command: "'/Applications/AMPPS/php-5.6/bin/php' 'artisan' inspire"
+expression: "* * * * * *"
+timezone: null
+user: null
+environments: []
+evenInMaintenanceMode: false
+withoutOverlapping: false
+runInBackground: false
#filters: []
#rejects: []
+output: "/dev/null"
#shouldAppendOutput: false
#beforeCallbacks: []
#afterCallbacks: []
+description: null
}
But when I remove dd() in schedule() function the output is
No scheduled commands are ready to run.
Can anyone help me and tell what I am doing wrong.
Check out the storage/framework folder for files like that schedule-d71c52cd9f206ba2359601745a5ad13d51fa7ca6
If any - delete them and try to run schedule:run command again.

Laravel 5.2 Cron job doesn't work

I want to create a cron job for test.
When i run the cron in log file appear the line but after not. I set cron job every minute.
I used php artisan schedule:run ..
Command dbTS
public function handle()
{
Log::info('Functioneaza !');
}
Console Kernel
protected function schedule(Schedule $schedule)
{
$schedule->command('dbTS:demo')
->everyMinute();
}
protected $commands = [
Commands\Inspire::class,
Commands\dbTS::class,
];

Resources