PHP code example of 10quality / scheduler

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

    

10quality / scheduler example snippets


// 1) LOAD COMPOSER AUTOLOAD OR BOOTSTRAP FIRST

// 2)
use Scheduler\Scheduler;

Scheduler::ready([
    'jobs'      => ['path' => __DIR__.'/jobs'],
    'session'   => ['driver' => 'file', 'path'=>__DIR__.'/.tmp'],
]);

Scheduler::ready([...])
    ->job('MyJob', function($task) {
        return $task->daily();
    });

Scheduler::ready([...])
    ->job(...)
    ->start();

use Scheduler\Base\Job;

class MyJob extends Job
{
    public function execute()
    {
        // My code here...
    }
}

Scheduler::ready([...])
    ->job('MyJob', function($task) {
        // Here we define the task interval
        return $task->daily();
    });

// On every execution
$task->now();

// Daily
$task->daily();

// Weekly
$task->weekly();

// Monthly
$task->monthly();

// Every minute
$task->everyMinute();

// Every 5 minutes
$task->everyFiveMinutes();

// Every 10 minutes
$task->everyTenMinutes();

// Every 30 minutes
$task->everyHalfHour();

// Every hour
$task->everyHour();

// Every 12 hours
$task->everyTwelveHours();

// Every 2 days
$task->everyTwoDays();

// Every 3 days
$task->everyThreeDays();

// Every XXX minutes (custom minutes)
// @param init $minutes Custome minutes interval
$task->custom($minutes);

Scheduler::ready([
    'jobs'      => ['path' => __DIR__.'/jobs'],
    'session'   => ['driver' => 'file', 'path'=>__DIR__.'/.tmp'],
    'events'    => [
                    'on_start' => function($microtime) {
                        // Do something during event
                    },
                    'on_job_start' => function($jobName, $microtime) {
                        if ($jobName === 'Job')
                            // Do something during event
                    }
                ],
]);

Scheduler::ready([
    'jobs'      => ['path' => __DIR__.'/jobs'],
    'session'   => ['driver' => 'file', 'path'=>__DIR__.'/.tmp'],
    'events'    => [
                    'on_exception' => function($e) {
                        // Do anything with exception
                        echo $e->getMessage();
                    }
                ],
]);

Scheduler::ready([...])
    ->job('MyJob', function($task) {
        // Here we define the task interval
        return $task->daily()
            ->onException(function($e) {
                // Do anything with exception
                echo $e->getMessage();
            });
    });

Scheduler::ready([...])
    ->job('MyJob', function($task) {
        // Here we define the task interval
        return $task->daily()
            ->canReset()
            ->onException(function(Exception $e) {
                // Do anything with exception
            });
    });

Scheduler::ready([
    'jobs'      => ['path' => __DIR__.'/jobs'],
    'session'   => ['driver' => 'file', 'path'=>__DIR__.'/.tmp'],
]);


use Scheduler\Contracts\Session;

class MySessionDriver implements Session
{
    /*
     * See and develop 

Scheduler::ready([
    'jobs'      => ['path' => __DIR__.'/jobs'],
    'session'   => [
                    'driver'    => 'callable',,
                    'callable'  => function() use(&$session) {
                        return MySessionDriver::load( $custom_options );
                    }
                ],
]);
bash
* * * * * php /path/to/scheduler-file.php >> /dev/null 2>&1