wppaste
WordPress

wp_check_php_mysql_versions()

Since
3.0.0
Source
wp-includes/load.php:157
Checks the server requirements.

Description

  • PHP version
    • PHP extensions
    • MySQL or MariaDB version (unless a database drop-in is present)

Dies if requirements are not met.

Compatibility

WordPress
since 3.0.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_check_php_mysql_versions() 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

Reads or writes the filesystem via file_exists().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
26–122

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • filesystemfilesystem accessfile_exists()called directly
  • hookthird-party callbacksapply_filters()one call below wp_check_php_mysql_versions()

Further down the call graph this can also reach query, option, cache, serialize 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 · 12 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_check_php_mysql_versions() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!version_compare() && function_exists()26–31version_compare(), function_exists()
!version_compare() && !function_exists() && file_exists()31–36version_compare(), function_exists(), file_exists()
!version_compare() && function_exists()43–48version_compare(), wp_get_server_protocol(), header(), header(), exit(), function_exists()
version_compare() && function_exists()47–52version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), function_exists()
!version_compare() && !function_exists() && file_exists()48–53version_compare(), wp_get_server_protocol(), header(), header(), exit(), function_exists(), file_exists()
version_compare() && !function_exists() && file_exists()52–57version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), function_exists(), file_exists()
version_compare() && function_exists()64–69version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), wp_get_server_protocol(), header(), header(), exit(), function_exists()
version_compare() && !function_exists() && file_exists()69–74version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), wp_get_server_protocol(), header(), header(), exit(), function_exists(), file_exists()
!version_compare() && !function_exists() && !file_exists()79–84version_compare(), function_exists(), file_exists(), wp_load_translations_early(), __(), __(), sprintf(), __(), __(), sprintf(), __(), wp_die(), exit()
!version_compare() && !function_exists() && !file_exists()96–101version_compare(), wp_get_server_protocol(), header(), header(), exit(), function_exists(), file_exists(), wp_load_translations_early(), __(), __(), sprintf(), __(), __(), sprintf(), __(), wp_die(), exit()
version_compare() && !function_exists() && !file_exists()100–105version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), function_exists(), file_exists(), wp_load_translations_early(), __(), __(), sprintf(), __(), __(), sprintf(), __(), wp_die(), exit()
version_compare() && !function_exists() && !file_exists()117–122version_compare(), wp_get_server_protocol(), header(), header(), printf(), exit(), wp_get_server_protocol(), header(), header(), exit(), function_exists(), file_exists(), wp_load_translations_early(), __(), __(), sprintf(), __(), __(), sprintf(), __(), wp_die(), exit()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13626–12210
8.513626–12210
8.413626–122103 fewer instructions than PHP 8.3
8.313926–8110
8.213926–8110
8.113926–81102 fewer instructions than PHP 7.4
7.414127–8210

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 · 4

Source code

function wp_check_php_mysql_versions() {	global $required_php_version, $required_php_extensions, $wp_version; 	$php_version = PHP_VERSION; 	if ( version_compare( $required_php_version, $php_version, '>' ) ) {		$protocol = wp_get_server_protocol();		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );		header( 'Content-Type: text/html; charset=utf-8' );		printf(			'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.',			$php_version,			$wp_version,			$required_php_version		);		exit( 1 );	} 	$missing_extensions = array(); 	if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {		foreach ( $required_php_extensions as $extension ) {			if ( extension_loaded( $extension ) ) {				continue;			} 			$missing_extensions[] = sprintf(				'WordPress %1$s requires the <code>%2$s</code> PHP extension.',				$wp_version,				$extension			);		}	} 	if ( count( $missing_extensions ) > 0 ) {		$protocol = wp_get_server_protocol();		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );		header( 'Content-Type: text/html; charset=utf-8' );		echo implode( '<br>', $missing_extensions );		exit( 1 );	} 	// This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet.	$wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content'; 	if ( ! function_exists( 'mysqli_connect' )		&& ! file_exists( $wp_content_dir . '/db.php' )	) {		require_once ABSPATH . WPINC . '/functions.php';		wp_load_translations_early(); 		$message = '<p>' . __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) . "</p>\n"; 		$message .= '<p>' . sprintf(			/* translators: %s: mysqli. */			__( 'Please check that the %s PHP extension is installed and enabled.' ),			'<code>mysqli</code>'		) . "</p>\n"; 		$message .= '<p>' . sprintf(			/* translators: %s: Support forums URL. */			__( 'If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress support forums</a>.' ),			__( 'https://wordpress.org/support/forums/' )		) . "</p>\n"; 		$args = array(			'exit' => false,			'code' => 'mysql_not_found',		);		wp_die(			$message,			__( 'Requirements Not Met' ),			$args		);		exit( 1 );	}}

Changelog

Introduced in 3.0.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 6.9.7 tag, from src/wp-includes/load.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.