PHP code example of evgeek / scheduler

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

    

evgeek / scheduler example snippets




use Doctrine\DBAL\DriverManager;
use Evgeek\Scheduler\Scheduler;
use Evgeek\Scheduler\Handler\DatabaseLogging;

ion(['url' => $uri]);

//Create new instance of the scheduler
$handler = new DatabaseLogging($conn);
$scheduler = new Scheduler($handler);

//Create, add to scheduler and setup new task
$scheduler->task(function() {
    echo 'Hello world!';
})
    ->schedule()
    ->every(1);

//Run the scheduler
$scheduler->run();

$scheduler->task(function() {echo 'Hello world!';});

$scheduler->task('ls -la');

$scheduler->task('/path/to/your/file.php');

$scheduler->task(new Job());

$scheduler->task([
    $scheduler->task(function() {echo 'Hello world!';}),
    $scheduler->task('ls -la'),
    $scheduler->task('/path/to/your/file.php'),
    $scheduler->task(new Job())
]);

$scheduler->task(new Job())
    ->schedule()
    ->every(60);

$scheduler->task(new Job())
    ->schedule()
    ->addInterval('00:00', '06:00')
    ->delay(5);

$scheduler->task(new Job())
    ->schedule()
    ->addInterval('03:00', '04:00')
    ->addInterval('15:00', '16:00')
    ->daysOfWeek([7]);

$scheduler->task(new Job())
    ->schedule()    
    ->daysOfWeek(['Mon', 'wednesday'])
    ->daysOfMonth([1])
    ->months(['Jan'])
    ->months(['Dec']);

$scheduler->task(new Job())
    ->schedule()    
    ->every(1)
    ->daysOfMonth([1])
    ->months(['Jan'])
    ->years([2022]);

$scheduler->task(new Job())
    ->schedule()    
    ->every(1)
    ->name('Job')
    ->description('A very useful task')
    ->tries(3);

//Creates and setup handler
$uri = 'mysql://user:secret@localhost/mydb';
$conn = \Doctrine\DBAL\DriverManager::getConnection(['url' => $uri]);
$handler = new \Evgeek\Scheduler\Handler\DatabaseLogging(
    $conn, 
    'scheduler_tasks', 
    'scheduler_launches'
);

//Creates and setup config
$config = new \Evgeek\Scheduler\Config(new Logger(), true);

//Creates scheduler with handler and (optional) config
$scheduler = new Scheduler($handler, $config);

/* ... */
$config = new \Evgeek\Scheduler\Config(null, true);
/* ... */
$scheduler->task('ls -la')
    ->schedule()
    ->delay(0)
    ->tries(3);

$exceptionLogMatching = [
    SoftException::class => Logger::NOTICE,
    FatalException::class => Logger::CRITICAL,    
    AbstractException::class => Logger::WARNING,
];
scheduler.php

* * * * * /usr/bin/php /path/to/your/scheduler.php
ERROR