PHP code example of semivan / php-scheduler

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

    

semivan / php-scheduler example snippets


$job = new \Scheduler\Job\BaseJob();

// Установка интервала (раз в неделю)
$job->setExpression('0 0 * * 0');

// Установка выполняемого метода
$job
    ->setCallableClass(CallableClass::class)
    ->setCallableMethod('callableMethod');

// CustomJob реализует интерфейс \Scheduler\Job\BaseJobInterface
$jobs = CustomJob::findAll();

$loader = new \Scheduler\Loader\BaseLoader();

// Добавление задания
$loader->addJob($job);
//$loader->addJobs($jobs);

$scheduler = new \Scheduler\Scheduler($loader);

// CustomLog реализует интерфейс \Scheduler\Log\BaseLogInterface
$loader->setLogClass(CustomLog::class);

$loader->setCallback([new CallableClass(), 'callback']);

$completedJobs = $scheduler->run();

$log = $scheduler->runJob($job);
$job->addLog($log);