PHP code example of faerber / laravel-kernel-cadence
1. Go to this page and download the library: Download faerber/laravel-kernel-cadence library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
faerber / laravel-kernel-cadence example snippets
// Before: every one of these fires at :00, :15, :30, :45
$schedule->command('tt:dailyOrders')->everyFifteenMinutes();
$schedule->command('tt:etsyNumbers')->everyFifteenMinutes();
$schedule->command('tt:tlmOrders')->everyFifteenMinutes();
// After: the same cadence, spread across the quarter hour
$schedule->command('tt:dailyOrders')->everyMinutes(15, offsetBy: 8);
$schedule->command('tt:etsyNumbers')->everyMinutes(15, offsetBy: 6);
$schedule->command('tt:tlmOrders')->everyMinutes(15, offsetBy: 10);
// Offset 2 minutes to spread the per-tenant fan-out load;
// everyFiveMinutes() has no offset modifier.
$schedule->command('ail:dispatchDueOrderReminders')->cron('2-59/5 * * * *');
use Faerber\KernelCadence\Scheduling\ApplicationSchedule;
use Faerber\KernelCadence\Testing\AssertsScheduleLoad;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleLoadDistributionTest extends TestCase {
use AssertsScheduleLoad;
private const MAX_TASKS_PER_MINUTE = 12;
public function test_no_single_minute_carries_a_disproportionate_share(): void {
$this->assertNoMinuteCarriesMoreThan(
self::MAX_TASKS_PER_MINUTE,
$this->hourlyRecurringLoad($this->schedule()),
);
}
public function test_the_top_of_the_hour_is_not_an_outlier(): void {
$this->assertTopOfTheHourIsNotAnOutlier($this->hourlyRecurringLoad($this->schedule()));
}
public function test_the_import_pipeline_stays_ordered(): void {
$this->assertRunsBefore('cron:orderRawImport', 'cron:orderImport', $this->schedule());
}
private function schedule(): Schedule {
return ApplicationSchedule::resolve($this->app);
}
}
use Faerber\KernelCadence\Analysis\ScheduleLoad;
$load = ScheduleLoad::ofHourlyRecurring($schedule);
$load->peak(); //=> MinuteLoad, ':00 (11 tasks)'
$load->at(15)->tasks; //=> 4
$load->exceeding(12); //=> list<MinuteLoad>, busiest first
$load->mean(); //=> 4.783333
$load->histogram(); //=> the bar chart above
// Before
$schedule->command('tt:dailyOrders')->cron(Cadence::everyMinutes(15, offsetBy: 8));
// After
$schedule->command('tt:dailyOrders')->everyMinutes(15, offsetBy: 8);
php artisan schedule:load --max=12
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.