WP_Site_Health::get_cron_tasks()
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-site-health.php:2935
Compatibility
- WordPress
- since 5.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to WP_Site_Health::get_cron_tasks() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 10–15
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 55.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()one call below WP_Site_Health::get_cron_tasks()
Further down the call graph this can also reach hook, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::get_cron_tasks() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($cron_tasks) | 10–11 | _get_cron_array() |
empty($cron_tasks) | 15 | _get_cron_array(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 55 | 10–15 | 8 | |
| 8.5 | 55 | 10–15 | 8 | |
| 8.4 | 55 | 10–15 | 8 | |
| 8.3 | 55 | 10–15 | 8 | |
| 8.2 | 55 | 10–15 | 8 | |
| 8.1 | 55 | 10–15 | 8 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 56 | 10–15 | 8 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 3
- _get_cron_array()Retrieves cron info array option.
- __()Retrieves the translation of $text.
- WP_Error::__construct()Initializes the error.
Used by · 1
- WP_Site_Health::wp_schedule_test_init()Initiates the WP_Cron schedule test cases.
Source code
private function get_cron_tasks() { $cron_tasks = _get_cron_array(); if ( empty( $cron_tasks ) ) { $this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) ); return; } $this->crons = array(); foreach ( $cron_tasks as $time => $cron ) { foreach ( $cron as $hook => $dings ) { foreach ( $dings as $sig => $data ) { $this->crons[ "$hook-$sig-$time" ] = (object) array( 'hook' => $hook, 'time' => $time, 'sig' => $sig, 'args' => $data['args'], 'schedule' => $data['schedule'], 'interval' => isset( $data['interval'] ) ? $data['interval'] : null, ); } } } }Changelog
Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/class-wp-site-health.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.