PHP code example of themehybrid / hybrid-action-scheduler

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

    

themehybrid / hybrid-action-scheduler example snippets


/*
 * Action scheduler.
 *
 * It needs to be called early because it hooks into `plugins_loaded`.
 *
 * @see https://actionscheduler.org/usage/#loading-action-scheduler
 */

$app->register( \Hybrid\Action\Scheduler\ActionSchedulerServiceProvider::class );

use function Hybrid\Action\Scheduler\queue;

queue()->add( 'my_hook', [ 'foo' => 'bar' ], 'my-group' );

use Hybrid\Action\Scheduler\Facades\Queue;

Queue::add( 'my_hook', [ 'foo' => 'bar' ], 'my-group' );

// Run once, at a specific time.
Queue::schedule_single( strtotime( 'tomorrow' ), 'my_hook', [ 'foo' => 'bar' ], 'my-group' );

// Run repeatedly at a fixed interval (in seconds).
Queue::schedule_recurring( time(), DAY_IN_SECONDS, 'my_hook', [], 'my-group' );

// Run on a cron-style schedule.
Queue::schedule_cron( time(), '0 0 * * *', 'my_hook', [], 'my-group' );

// Cancel the next scheduled instance (and any recurring instances after it).
Queue::cancel( 'my_hook', [ 'foo' => 'bar' ], 'my-group' );

// Cancel all scheduled instances.
Queue::cancel_all( 'my_hook' );

// Get the next scheduled run time.
$next = Queue::get_next( 'my_hook' );

// Search for scheduled actions.
$actions = Queue::search( [ 'hook' => 'my_hook', 'status' => 'pending' ] );

add_action( 'my_hook', function ( $foo ) {
    // Handle the job.
} );