class-cron.php

Cron Class for scheduling and managing cron jobs in the PerformanceOptimise plugin.

Source includes/Scheduler/class-cron.php8 min readPart of Performance Optimisation

includes/Scheduler/class-cron.php

Cron Class for scheduling and managing cron jobs in the PerformanceOptimise plugin.

Namespace: PerformanceOptimise\\Inc · Lines: 1792

Class Cron

Class Cron

Source: includes/Scheduler/class-cron.php, line 36

class Cron

Tags: @since 1.0.0

Constants

ConstantVisibilityValueLine
PRELOAD_QUEUE_OPTIONpublic\'wppo_preload_queue\'48
PRELOAD_RESUME_CHUNK_SIZEprivate50372
TO_FETCH_LIMITprivate50379
SCHEDULED_HOOKSpublicJob_Registry::CRON_HOOKS401
AS_HOOKSpublicJob_Registry::AS_HOOKS412

publicstatic get_preload_queue()

public static function get_preload_queue(): array

Read the resumable sitemap preload queue.

Return: array{queued:string[],done:int,failed:string[],total:int,status:string,updated_at:int}.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 56

privatestatic save_preload_queue()

private static function save_preload_queue(array $queue): void

Persist the preload queue (fail-open, never fatal).

ParameterTypeDefaultDescription
$queuearray—Queue payload.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 96

publicstatic init_preload_queue()

public static function init_preload_queue(array $urls): void

Seed or extend the preload queue with freshly scheduled URLs.

ParameterTypeDefaultDescription
$urlsarray—Freshly scheduled sitemap URLs.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 119

publicstatic mark_preload_done()

public static function mark_preload_done(string $url): void

Mark a sitemap URL as done (removes it from queued, bumps done).

ParameterTypeDefaultDescription
$urlstring—Preloaded URL.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 148

publicstatic mark_preload_failed()

public static function mark_preload_failed(string $url): void

Mark a sitemap URL as failed (removes it from queued).

ParameterTypeDefaultDescription
$urlstring—Failed URL.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 178

publicstatic get_preload_status()

public static function get_preload_status(): array

Honest preload progress counters for the SPA.

Return: array{queued:int,done:int,failed:int,total:int,status:string,failed_urls:string[],cache_bytes:int,cache_files:int,stalled:bool}.

Tags: @since 2.2.0 · @since 2.3.0 Bytes-aware payload (issue #1428): `cache_bytes`/`cache_files`/`stalled` fields plus zero-byte downgrade.

Source: includes/Scheduler/class-cron.php, line 221

publicstatic resume_preload_queue()

public static function resume_preload_queue(): int

Resume the preload queue by re-scheduling queued + failed URLs.

Return: int — Number of URLs re-scheduled.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 295

public preload_url_batch()

public function preload_url_batch($urls): void

Process a resumed preload batch (chunk of URLs).

ParameterTypeDefaultDescription
$urlsmixed—Chunk of URLs to preload.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 342

public __construct()

public function __construct()

Constructor: registers the actions and filters used to schedule and run the plugin\’s cron jobs (audit #1362: hooks docblock moved here from the constants block so IDEs attach it correctly).

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 431

publicstatic trigger_preload()

public static function trigger_preload(): void

Trigger the cache preload directly (not via cron hook).

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 463

public add_custom_cron_interval()

public function add_custom_cron_interval($schedules): array

Add a custom cron interval.

ParameterTypeDefaultDescription
$schedulesarray—Existing cron schedules.

Return: array — Modified schedules with \’every_5_hours\’ added.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 478

public schedule_cron_jobs()

public function schedule_cron_jobs(): void

Schedule the main cron job that triggers the processing of all pages.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 505

private is_object_cache_circuit_open()

private function is_object_cache_circuit_open(): bool

Whether the object-cache circuit breaker is currently open.

Return: bool — True when the circuit is open.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 557

public object_cache_probe_cron()

public function object_cache_probe_cron(): void

Callback for the object-cache recovery probe cron.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 584

public llms_txt_cron()

public function llms_txt_cron(): void

Callback for LLMs.txt daily regeneration cron.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 608

public ccss_regeneration_cron()

public function ccss_regeneration_cron()

Callback for CCSS daily regeneration cron.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 624

public web_vitals_rescan_cron()

public function web_vitals_rescan_cron(): void

Callback for the daily Web Vitals auto-rescan cron.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 648

public wppo_page_cron_callback()

public function wppo_page_cron_callback(): void

Triggers scheduling of the next batch of per-page static-generation jobs.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 718

private schedule_page_cron_jobs()

private function schedule_page_cron_jobs(): void

Schedules per-page static-generation cron events in paged batches.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 737

private schedule_sitemap_url_jobs()

private function schedule_sitemap_url_jobs(array $exclude_urls): void

Schedule single cron events for sitemap-discovered URLs.

ParameterTypeDefaultDescription
$exclude_urlsarray—Exclusion rules (processed URLs/patterns).

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 907

private is_woo_excluded_url()

private function is_woo_excluded_url(string $url, ?bool=null $woo_safe, ?array=null $woo_paths): bool

Whether a preload URL targets a WooCommerce dynamic route.

ParameterTypeDefaultDescription
$urlstring—Absolute URL.
$woo_safe?bool=null—Optional pre-resolved safe-mode flag (hoisted by batch callers).
$woo_paths?array=null—Optional pre-resolved Woo excluded paths (hoisted by batch callers).

Return: bool — True when the URL must not be preloaded.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 980

private is_editor_preview_url()

private function is_editor_preview_url(string $url): bool

Whether a preload URL targets an admin or editor-preview context.

ParameterTypeDefaultDescription
$urlstring—Absolute URL.

Return: bool — True when the URL must not be preloaded.

Tags: @since 2.2.0

Source: includes/Scheduler/class-cron.php, line 1104

private get_scheduled_args_set()

private function get_scheduled_args_set(string $hook): ?array

Snapshot scheduled args for a cron hook into an in-memory set.

ParameterTypeDefaultDescription
$hookstring—Cron hook name.

Return: array<string, — bool>|null Args set, or null on fallback.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1151

private is_hook_arg_scheduled()

private function is_hook_arg_scheduled(string $hook, array $args, ?array $scheduled): bool

Whether a hook+args event is already scheduled.

ParameterTypeDefaultDescription
$hookstring—Hook name.
$argsarray—Event args.
$scheduled?array——

Return: bool — True when already scheduled.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1193

private get_rest_route_param()

private function get_rest_route_param(string $url, string $query): string

Extract the `rest_route` query value from a preload URL.

ParameterTypeDefaultDescription
$urlstring—Absolute URL.
$querystring—Pre-parsed query string.

Return: string — The `rest_route` value or \’\’.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1220

public used_css_cron()

public function used_css_cron()

Callback for used-CSS background regeneration cron.

Return: void.

Tags: @since 1.9.0

Source: includes/Scheduler/class-cron.php, line 1240

publicstatic clear_cron_jobs()

public static function clear_cron_jobs(): void

Clear all scheduled cron jobs.

Return: void.

Tags: @since 1.0.0 · @since 2.0.0 Derived from Cron::SCHEDULED_HOOKS; added wppo_img_conversion and wppo_database_cleanup_cron.

Source: includes/Scheduler/class-cron.php, line 1272

public process_page()

public function process_page($page_id): void

Process a specific page by generating its static version.

ParameterTypeDefaultDescription
$page_idint—The ID of the page to process.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 1296

public process_url()

public function process_url($url): void

Generate a static cache file for an arbitrary URL.

ParameterTypeDefaultDescription
$urlstring—The URL to preload.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1327

public get_sitemap_urls()

public function get_sitemap_urls(int=500 $cap): array

Discover preloadable URLs from the site\’s sitemap.

ParameterTypeDefaultDescription
$capint=500—Maximum number of URLs to return.

Return: string[] — List of absolute sitemap URLs.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1411

private load_page()

private function load_page($page_id): void

Load a specific page.

ParameterTypeDefaultDescription
$page_idint—The ID of the page to load.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 1496

public litespeed_crawler_batch()

public function litespeed_crawler_batch($arg): void

Crawl batch via curl_multi variant matrix (P4).

ParameterTypeDefaultDescription
$argstring|string[]—Batch ID or URL list.

Return: void.

Tags: @since 2.0.0 Accepts batch-ID arguments and cleans up the transient.

Source: includes/Scheduler/class-cron.php, line 1532

privatestatic peek_crawler_batch_arg()

private static function peek_crawler_batch_arg($arg): array

Resolve a deferred crawler batch argument into its URL list without deleting the payload.

ParameterTypeDefaultDescription
$argmixed—Batch ID or URL list.

Return: string[] — URLs to crawl.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1566

public crawler_warm_single()

public function crawler_warm_single($url): void

Warm a single URL via crawler (post-publish lane).

ParameterTypeDefaultDescription
$urlstring—URL.

Return: void.

Tags: @since 2.0.0

Source: includes/Scheduler/class-cron.php, line 1582

private mark_page_as_processed()

private function mark_page_as_processed($page_id): void

Mark a page as processed by clearing any previously generated cache files.

ParameterTypeDefaultDescription
$page_idint—The ID of the page to mark as processed.

Return: void.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 1603

public img_convert_cron()

public function img_convert_cron()

Convert images to optimized formats.

Tags: @since 1.0.0

Source: includes/Scheduler/class-cron.php, line 1669

public database_cleanup_cron()

public function database_cleanup_cron()

Callback for database automatic cleanup cron.

Return: void.

Tags: @since 1.3.0

Source: includes/Scheduler/class-cron.php, line 1748

Hooks

Hooks referenced in includes/Scheduler/class-cron.php:

HookTypeLineNotes
wppo_page_cron_hookaction registration433—
wppo_page_cron_batchaction registration434—
wppo_img_conversionaction registration435—
wppo_generate_static_pageaction registration438—
wppo_generate_static_urlaction registration439—
wppo_preload_url_batchaction registration440—
wppo_litespeed_crawler_batchaction registration441—
wppo_crawler_warmaction registration442—
wppo_database_cleanup_cronaction registration444—
wppo_web_vitals_rescanaction registration446—
wppo_llms_txt_dailyaction registration448—
wppo_used_css_cronaction registration450—
wppo_ccss_regenerationaction registration451—
wppo_rum_flushaction registration452—
wppo_object_cache_probeaction registration453—
wppo_object_cache_probe_intervalfilter490@param ×1
wppo_cron_discovery_limitfilter1702—