Skip to content

Instantly share code, notes, and snippets.

@thedom85
Last active July 6, 2022 13:56
Show Gist options
  • Save thedom85/9339fec821b19bab037e9ba9637b5250 to your computer and use it in GitHub Desktop.
Save thedom85/9339fec821b19bab037e9ba9637b5250 to your computer and use it in GitHub Desktop.

Laravel schedule

Step 1 : Configure cron

crontab -e
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Step2 : Modify Kernel.php

class Kernel extends ConsoleKernel
{
    ... 
    
    protected function schedule(Schedule $schedule)
    {
       // example command
       $schedule->command('demo:cron')->dailyAt('10:00')->timezone('Europe/Paris');

      // example exec 
      $schedule->exec('/usr/local/bin/node ' . storage_path('scripts/test/') .'main.js' )->everyMinute();
    }

 ....
 
}

Command in solution

php artisan  schedule:run
php artisan  schedule:list

Register as Task Scheduler

Command Description
everyMinute(); Run the task every minute
everyFiveMinutes(); Run the task every five minutes
everyTenMinutes(); Run the task every ten minutes
everyFifteenMinutes(); Run the task every fifteen minutes
everyThirtyMinutes(); Run the task every thirty minutes
hourly(); Run the task every hour
hourlyAt(17); Run the task every hour at 17 mins past the hour
daily(); Run the task every day at midnight
dailyAt(’13:00′); Run the task every day at 13:00
twiceDaily(1, 13); Run the task daily at 1:00 & 13:00
weekly(); Run the task every week
weeklyOn(1, ‘8:00’); Run the task every week on Tuesday at 8:00
monthly(); Run the task every month
monthlyOn(4, ’15:00′); Run the task every month on the 4th at 15:00
quarterly(); Run the task every quarter
yearly(); Run the task every year
timezone(‘America/New_York’); Set the timezone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment