Laravel 5.0 - Event Scheduling
This is a series of posts on New Features in Laravel 5.0.
!Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.
Eric Barnes has a longer write up on this, so I'll just keep it short:
Laravel 5.0 is introducing a pretty incredible cron-style scheduler (similar to Indatus' Dispatcher) built into the core. Just point a cron job that's scheduled once a minute at artisan schedule:run
and you're good to go.
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
For example, you can now bind the following event to clear your auth reminders daily:
$schedule
->command('auth:clear-reminders')
->daily()
->sendOutputTo($logPath)
->emailOutputTo('me@me.com');
You can use commmand()
to call artisan commands, call
to call methods or functions, or terminal()
to run command line scripts:
$schedule->call('YourClass@someMethod')->twiceDaily();
$schedule->call(function() {
// Do stuff
})->everyFiveMinutes();
$schedule->terminal('cp oldThing newThing')->dailyAt('8:00');
You can also use a callback to decide when something will or won't run, using when()
or skip()
:
$schedule
->call('Mailer@BusinessDayMailer')
->weekdays()
->skip(function(TypeHintedDeciderClass $decider)
{
return $decider->isHoliday();
}
);
This is just a quick introduction, though; check out Eric's post for a fuller rundown: Laravel 5 Scheduler on Laravel-News
Comments? I'm @stauffermatt on Twitter
Tags: laravel • 5.0 • laravel 5
This is part of a series of posts on New Features in Laravel 5.0:
-
Sep 10, 2014 | laravel, 5.0, laravel 5
-
Sep 10, 2014 | laravel, 5.0, laravel 5
-
Sep 12, 2014 | laravel, laravel 5, 5.0
-
Sep 20, 2014 | laravel, 5.0, laravel 5
-
Sep 28, 2014 | laravel, laravel 5, 5.0
-
Sep 30, 2014 | laravel, 5.0, laravel 5
-
Oct 9, 2014 | laravel, 5.0, laravel 5
-
Oct 10, 2014 | laravel, 5.0, laravel 5
-
Oct 10, 2014 | laravel, 5.0, laravel 5
-
Oct 16, 2014 | laravel, 5.0, laravel 5
-
Nov 20, 2014 | laravel, 5.0, laravel 5
-
Jan 2, 2015 | laravel, 5.0, commands, laravel 5
-
Jan 16, 2015 | laravel, laravel 5
-
Jan 19, 2015 | laravel 5, laravel
-
Jan 21, 2015 | laravel, events, 5.0, laravel 5
-
Jan 26, 2015 | laravel, laravel 5
-
Feb 1, 2015 | laravel, laravel 5
-
Feb 14, 2015 | laravel 5, laravel, eloquent