Installation
Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.0 |
| WordPress | 6.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:
- Registers a
Schedulesingleton in the container (accessible viaSchedule::classor'scheduler') - Adds a custom
every_minutecron schedule to WordPress - Hooks into WP-Cron to run all due tasks on each minute tick
- Schedules the recurring cron event on
initif 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.