PHP code example of freewinds / laravel-short-schedule

1. Go to this page and download the library: Download freewinds/laravel-short-schedule 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/ */

    

freewinds / laravel-short-schedule example snippets


// in app\Console\Kernel.php

protected function shortSchedule(\Spatie\ShortSchedule\ShortSchedule $shortSchedule)
{
    // this command will run every second
    $shortSchedule->command('artisan-command')->everySecond();
    
    // this command will run every 30 seconds
    $shortSchedule->command('another-artisan-command')->everySeconds(30);
    
    // this command will run every half a second
    $shortSchedule->command('another-artisan-command')->everySeconds(0.5);
    
    // this command will run every second and its signature will be retrieved from command automatically
    $shortSchedule->command(\Spatie\ShortSchedule\Tests\Unit\TestCommand::class)->everySecond();
}

// in app\Console\Kernel.php

protected function shortSchedule(\Spatie\ShortSchedule\ShortSchedule $shortSchedule)
{
    // this artisan command will run every second
    $shortSchedule->command('artisan-command')->everySecond();
    
    // this artisan command will run every second, its signature will be resolved from container
    $shortSchedule->command(\Spatie\ShortSchedule\Tests\Unit\TestCommand::class)->everySecond();
}

$shortSchedule->command('artisan-command')->everySecond();

$shortSchedule->command('artisan-command')->everySeconds(30);

$shortSchedule->command('artisan-command')->everySeconds(0.5);

$shortSchedule->exec('bash-command')->everySecond();

$shortSchedule->command('artisan-command')->everySecond()->withoutOverlapping();

 $shortSchedule->command('artisan-command')->between('09:00', '17:00')->everySecond();
 

 $shortSchedule->command('artisan-command')->between('21:00', '01:00')->everySecond();
 

$shortSchedule->command('artisan-command')->when(fn() => rand() %2)->everySecond();

 $shortSchedule->command('artisan-command')->environment('production')->everySecond();
 

 $shortSchedule->command('artisan-command')->environment(['staging', 'production'])->everySecond();
 

 $shortSchedule
   ->command('artisan-command')
   ->between('09:00', '17:00')
   ->when($callable)
   ->everySecond();
 

$shortSchedule->command('artisan-command')->everySecond()->runInMaintenanceMode();

$shortSchedule->command('artisan-command')->everySecond()->onOneServer();
bash
php artisan short-schedule:run
bash
cp ./vendor/spatie/laravel-short-schedule/src/Commands/ShortScheduleRunCommand.php ./app/Console/Commands/ShortScheduleRunCommand.php