wppaste
WordPress

WP_Automatic_Updater::has_fatal_error(): bool

Since
6.6.0
Source
wp-admin/includes/class-wp-automatic-updater.php:1761
Performs a loopback request to check for potential fatal errors.

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

Reaches an outbound HTTP request via wp_remote_get().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–147

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 157.

Plugin surface
1 hook

Third-party callbacks on 'https_local_ssl_verify' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • transienttransientset_transient()called directly
  • hookthird-party callbacksapply_filters()called directly
  • httpoutbound HTTP requestwp_remote_get()called directly
  • serializeserialisationjson_decode()called directly
  • filesystemfilesystem accessfile_exists()called directly
  • cacheobject cachewp_cache_set()one call below WP_Automatic_Updater::has_fatal_error()
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
always9–12file_exists()
file_exists() && is_int($upgrading) && !isset($value) && is_wp_error()81–86file_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–89file_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–92file_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–95file_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 === false94–99file_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 === false97–102file_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–106file_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 === false105–110file_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–109file_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 !== false108–113file_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 === false108–113file_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–112file_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 !== false111–116file_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–115file_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 === false117–119file_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 !== false119–124file_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 === false120–122file_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 !== false122–127file_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 === false128–130file_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 !== false131–133file_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 === false131–133file_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 !== false134–136file_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 !== false142–144file_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 !== false145–147file_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

PHPCompiledExecutedBranchesNotes
8.6-dev1579–14710
8.51579–14710
8.41579–1471020 fewer instructions than PHP 8.3
8.31779–16710
8.21779–16710
8.11779–16710
7.41779–16710

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:

  1. 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

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.