Installation

Requirements

RequirementVersion
PHP^8.0
WordPress6.0+
wpzylos-core^1.0

Install via Composer

composer require KYNetCode/wpzylos-scheduler

Register the ServiceProvider

Add the SchedulerServiceProvider to your plugin's service provider registration:

use WPZylos\Framework\Scheduler\SchedulerServiceProvider;

// In your plugin bootstrap or Application setup
$app->register(new SchedulerServiceProvider());

Or if your application uses a providers array:

'providers' => [
    // ... other providers
    WPZylos\Framework\Scheduler\SchedulerServiceProvider::class,
],

What the ServiceProvider Does

When registered, the SchedulerServiceProvider:

  1. Registers a Schedule singleton in the container (accessible via Schedule::class or 'scheduler')
  2. Adds a custom every_minute cron schedule to WordPress
  3. Hooks into WP-Cron to run all due tasks on each minute tick
  4. Schedules the recurring cron event on init if not already scheduled

Verify Installation

// Check that the scheduler is available
$schedule = $app->make(Schedule::class);

// Register a test task
$schedule->call(function () {
    error_log('Scheduler is working!');
})->everyMinute()->name('test-scheduler');

// Verify tasks are registered
var_dump($schedule->hasTasks()); // true
var_dump(count($schedule->getTasks())); // 1

Production Cron Setup

For reliable execution, disable WordPress's default "on-request" cron and use a system-level cron job:

// wp-config.php
define('DISABLE_WP_CRON', true);

Then add a system cron job:

# Linux/macOS
* * * * * curl -s https://yoursite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

# Or using WP-CLI
* * * * * cd /path/to/wordpress && wp cron event run --due-now > /dev/null 2>&1

This ensures tasks execute precisely on schedule, regardless of site traffic.