PHP code example of jeffreyvanrossum / wp-job-scheduler

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

    

jeffreyvanrossum / wp-job-scheduler example snippets


WPJobScheduler::instance()
    ->projectRootPath(__DIR__)
    ->scheduler(function() {
        ExampleJob::schedule('hourly');
    })
    ->boot();

ExampleJob::dispatch();

ExampleJob::dispatch(function($job) {
    $job->withDelay(30);
});

ExampleJob::dispatch(function($job) {
    $job->withDelay(30);
}, ['foo' => 'bar']);

class ExampleJob implements Jobable
{
    use IsJob, Schedulable, Dispatchable;

    public function handle()
    {
        // the actual handling of the job
    }

    public function before(): void
    {
        // before the job has been handled
    }

    public function after(): void
    {
        // after the job has been handled
    }

    public function catch(Throwable $e): void
    {
        // do something with exception
    }
}