WP_Automatic_Updater::has_fatal_error(): bool
- Since
- 6.6.0
- Source
wp-admin/includes/class-wp-automatic-updater.php:1761
Description
Fatal errors cannot be detected unless maintenance mode is enabled.
Compatibility
- WordPress
- since 6.6.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
bool- Whether a fatal error was detected.
Performance profile
How much work a call to WP_Automatic_Updater::has_fatal_error() 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
- 9–147
- Plugin surface
- 1 hook
- Called by
- 1
Reaches an outbound HTTP request via wp_remote_get().
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 157.
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
- transienttransient
set_transient()called directly - hookthird-party callbacks
apply_filters()called directly - httpoutbound HTTP request
wp_remote_get()called directly - serializeserialisation
json_decode()called directly - filesystemfilesystem access
file_exists()called directly - cacheobject cache
wp_cache_set()one call below WP_Automatic_Updater::has_fatal_error() - optionoption read or write
get_option()one call below WP_Automatic_Updater::has_fatal_error()
Further down the call graph this can also reach query. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 25 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Automatic_Updater::has_fatal_error() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9–12 | file_exists() |
file_exists() && is_int($upgrading) && !isset($value) && is_wp_error() | 81–86 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error() |
file_exists() && is_int($upgrading) && !isset($value) && is_wp_error() | 84–89 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error() |
file_exists() && is_int($upgrading) && !isset($value) && is_wp_error() | 87–92 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), ->get_error_message(), error_log() |
file_exists() && is_int($upgrading) && !isset($value) && is_wp_error() | 90–95 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), ->get_error_message(), error_log() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position === false | 94–99 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position === false | 97–102 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && is_wp_error() | 104–106 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position === false | 105–110 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && is_wp_error() | 107–109 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position !== false | 108–113 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position === false | 108–113 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), delete_transient() |
13 further outcomes, up to 147 instructions
file_exists() && is_int($upgrading) && isset($value) && is_wp_error() | 110–112 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), ->get_error_message(), error_log() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position !== false | 111–116 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && is_wp_error() | 113–115 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), ->get_error_message(), error_log() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position === false | 117–119 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position !== false | 119–124 | file_exists(), md5(), set_transient(), wp_unslash(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position === false | 120–122 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && !isset($value) && !is_wp_error() && $scrape_result_position !== false | 122–127 | file_exists(), md5(), set_transient(), wp_unslash(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position === false | 128–130 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position !== false | 131–133 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position === false | 131–133 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position !== false | 134–136 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position !== false | 142–144 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
file_exists() && is_int($upgrading) && isset($value) && !is_wp_error() && $scrape_result_position !== false | 145–147 | file_exists(), md5(), set_transient(), wp_unslash(), wp_unslash(), wp_unslash(), base64_encode(), error_log(), home_url(), add_query_arg(), apply_filters(), compact(), wp_remote_get(), is_wp_error(), var_export(), error_log(), wp_remote_retrieve_body(), json_decode(), delete_transient() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 157 | 9–147 | 10 | |
| 8.5 | 157 | 9–147 | 10 | |
| 8.4 | 157 | 9–147 | 10 | 20 fewer instructions than PHP 8.3 |
| 8.3 | 177 | 9–167 | 10 | |
| 8.2 | 177 | 9–167 | 10 | |
| 8.1 | 177 | 9–167 | 10 | |
| 7.4 | 177 | 9–167 | 10 |
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_Automatic_Updater::has_fatal_error() runs, in this order:
- apply_filters( https_local_ssl_verify )filterline 1806 (+45 into the body)
Filters whether SSL should be verified for local HTTP API requests.
Uses · 9
- set_transient()Sets/updates the value of a transient.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- add_query_arg()Retrieves a modified URL query string.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_remote_get()Performs an HTTP request using the GET method and returns its response.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_remote_retrieve_body()Retrieves only the body from the raw response.
- delete_transient()Deletes a transient.
Used by · 1
- WP_Automatic_Updater::update()Updates an item, if appropriate.
Source code
protected function has_fatal_error() { global $upgrading; $maintenance_file = ABSPATH . '.maintenance'; if ( ! file_exists( $maintenance_file ) ) { return false; } require $maintenance_file; if ( ! is_int( $upgrading ) ) { return false; } $scrape_key = md5( $upgrading ); $scrape_nonce = (string) $upgrading; $transient = 'scrape_key_' . $scrape_key; set_transient( $transient, $scrape_nonce, 30 ); $cookies = wp_unslash( $_COOKIE ); $scrape_params = array( 'wp_scrape_key' => $scrape_key, 'wp_scrape_nonce' => $scrape_nonce, ); $headers = array( 'Cache-Control' => 'no-cache', ); // Include Basic auth in the loopback request. 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'] ) ); } // Time to wait for loopback request to finish. $timeout = 50; // 50 seconds. $is_debug = WP_DEBUG && WP_DEBUG_LOG; if ( $is_debug ) { error_log( ' Scraping home page...' ); } $needle_start = "###### wp_scraping_result_start:$scrape_key ######"; $needle_end = "###### wp_scraping_result_end:$scrape_key ######"; $url = add_query_arg( $scrape_params, home_url( '/' ) ); /** This filter is documented in wp-includes/class-wp-http-streams.php */ $sslverify = apply_filters( 'https_local_ssl_verify', false, $url ); $response = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) ); if ( is_wp_error( $response ) ) { if ( $is_debug ) { error_log( 'Loopback request failed: ' . $response->get_error_message() ); } return true; } // If this outputs `true` in the log, it means there were no fatal errors detected. if ( $is_debug ) { error_log( var_export( substr( $response['body'], strpos( $response['body'], '###### wp_scraping_result_start:' ) ), true ) ); } $body = wp_remote_retrieve_body( $response ); $scrape_result_position = strpos( $body, $needle_start ); $result = null; if ( false !== $scrape_result_position ) { $error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) ); $error_output = substr( $error_output, 0, strpos( $error_output, $needle_end ) ); $result = json_decode( trim( $error_output ), true ); } delete_transient( $transient ); // Only fatal errors will result in a 'type' key. return isset( $result['type'] ); }Changelog
Introduced in 6.6.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 7.1.0 tag, from
src/wp-admin/includes/class-wp-automatic-updater.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.