WP_Site_Health::can_perform_loopback(): object
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-site-health.php:3184
Description
Loopbacks are what WordPress uses to communicate with itself to start up WP_Cron, scheduled posts, make sure plugin or theme edits don't cause site failures and similar.
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.
Return value
object- The test results.
Performance profile
How much work a call to WP_Site_Health::can_perform_loopback() 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
- Expensive
- Scaling
- Constant
- Instructions
- 49–82
- Plugin surface
- 1 hook
- Called by
- 1
Reaches an outbound HTTP request via wp_remote_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 108.
Third-party callbacks on 'https_local_ssl_verify' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - httpoutbound HTTP request
wp_remote_post()called directly
Further down the call graph this can also reach option, 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::can_perform_loopback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && !is_wp_error() | 49–52 | wp_unslash(), apply_filters(), site_url(), compact(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), __() |
!isset($value) && !is_wp_error() | 56–59 | wp_unslash(), apply_filters(), site_url(), compact(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), __(), wp_remote_retrieve_response_code(), sprintf() |
!isset($value) && is_wp_error() | 59–62 | wp_unslash(), apply_filters(), site_url(), compact(), wp_remote_post(), is_wp_error(), __(), __(), ->get_error_message(), ->get_error_code(), sprintf() |
isset($value) && !is_wp_error() | 72 | wp_unslash(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), site_url(), compact(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), __() |
isset($value) && !is_wp_error() | 79 | wp_unslash(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), site_url(), compact(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), __(), wp_remote_retrieve_response_code(), sprintf() |
isset($value) && is_wp_error() | 82 | wp_unslash(), apply_filters(), wp_unslash(), wp_unslash(), base64_encode(), site_url(), compact(), wp_remote_post(), is_wp_error(), __(), __(), ->get_error_message(), ->get_error_code(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 108 | 49–82 | 4 | |
| 8.5 | 108 | 49–82 | 4 | |
| 8.4 | 108 | 49–82 | 4 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 110 | 49–84 | 4 | |
| 8.2 | 110 | 49–84 | 4 | |
| 8.1 | 110 | 49–84 | 4 | |
| 7.4 | 110 | 49–84 | 4 |
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.
Hooks and filters fired · 1
One hook fires while WP_Site_Health::can_perform_loopback() runs, in this order:
- apply_filters( https_local_ssl_verify )filterline 3192 (+8 into the body)
Filters whether SSL should be verified for local HTTP API requests.
Uses · 7
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- wp_remote_post()Performs an HTTP request using the POST method and returns its response.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- __()Retrieves the translation of $text.
- wp_remote_retrieve_response_code()Retrieves only the response code from the raw response.
Used by · 1
- WP_Site_Health::get_test_loopback_requests()Tests if loopbacks work as expected.
Source code
public function can_perform_loopback() { $body = array( 'site-health' => 'loopback-test' ); $cookies = wp_unslash( $_COOKIE ); $timeout = 10; // 10 seconds. $headers = array( 'Cache-Control' => 'no-cache', ); /** This filter is documented in wp-includes/class-wp-http-streams.php */ $sslverify = apply_filters( 'https_local_ssl_verify', false ); // Include Basic auth in loopback requests. if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); } $url = site_url( 'wp-cron.php' ); /* * A post request is used for the wp-cron.php loopback test to cause the file * to finish early without triggering cron jobs. This has two benefits: * - cron jobs are not triggered a second time on the site health page, * - the loopback request finishes sooner providing a quicker result. * * Using a POST request causes the loopback to differ slightly to the standard * GET request WordPress uses for wp-cron.php loopback requests but is close * enough. See https://core.trac.wordpress.org/ticket/52547 */ $r = wp_remote_post( $url, compact( 'body', 'cookies', 'headers', 'timeout', 'sslverify' ) ); if ( is_wp_error( $r ) ) { return (object) array( 'status' => 'critical', 'message' => sprintf( '%s<br>%s', __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ), sprintf( /* translators: 1: The WordPress error message. 2: The WordPress error code. */ __( 'Error: %1$s (%2$s)' ), $r->get_error_message(), $r->get_error_code() ) ), ); } if ( 200 !== wp_remote_retrieve_response_code( $r ) ) { return (object) array( 'status' => 'recommended', 'message' => sprintf( /* translators: %d: The HTTP response code returned. */ __( 'The loopback request returned an unexpected http status code, %d, it was not possible to determine if this will prevent features from working as expected.' ), wp_remote_retrieve_response_code( $r ) ), ); } return (object) array( 'status' => 'good', 'message' => __( 'The loopback request to your site completed successfully.' ), ); }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.9.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.