PHP code example of andrewdyer / scheduler

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

    

andrewdyer / scheduler example snippets


// SendReminderJob.php
namespace App\Jobs;

use Anddye\Scheduler\AbstractJob;

class SendReminderJob extends AbstractJob
{
    public function handle(): void
    {
        // TODO: Send reminder to user somehow
    }
}

// index.php
$scheduler = new Anddye\Scheduler\Scheduler();

// At every 45th minute, run the send reminder job.
$scheduler->addJob(new App\Jobs\SendReminderJob())->setExpression('*/45 * * * *');

// add more jobs ...

$scheduler->run();

// At minute 0 past hour 2 and 14 on Monday
$scheduler->addJob(new App\Jobs\SendReminderJob())->dailyTwice(2, 14)->mondays();

// At every 15th minute on Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->everyFifteenMinutes()->fridays();

// At every minute on Tuesday, Thursday, and Saturday
$scheduler->addJob(new App\Jobs\SendReminderJob())->everyMinute()->days(2, 4, 6);

// At minute 45 on Monday, Tuesday, Wednesday, Thursday, and Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->hourlyAt(45)->weekdays();

// At minute 1 on Monday, Wednesday, and Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->hourly()->days(1,3,5);