PHP code example of dima-bzz / laravel-short-schedule

1. Go to this page and download the library: Download dima-bzz/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/ */

    

dima-bzz / 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();
}

$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();

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

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

Execution #1 in 11/25/2020 2:03:33 PM output:
Running command: echo 'called'

Execution #2 in 11/25/2020 2:03:32 PM output:
Skipping command (still is running): echo 'called'

Execution #3 in 11/25/2020 2:05:32 PM output:
Skipping command (system is down): echo 'called'

Execution #4 in 11/25/2020 2:15:32 PM output:
Skipping command (has already run on another server): echo 'called'