WP_Debug_Data::get_wp_server()private staticWP 6.7.0

Gets the WordPress server section of the debug data.

Method of the class: WP_Debug_Data{}

No Hooks.

Return

Array.

Usage

$result = WP_Debug_Data::get_wp_server(): array;

Changelog

Since 6.7.0 Introduced.

WP_Debug_Data::get_wp_server() code WP 6.8

private static function get_wp_server(): array {
	// Populate the server debug fields.
	if ( function_exists( 'php_uname' ) ) {
		$server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
	} else {
		$server_architecture = 'unknown';
	}

	$php_version_debug = PHP_VERSION;
	// Whether PHP supports 64-bit.
	$php64bit = ( PHP_INT_SIZE * 8 === 64 );

	$php_version = sprintf(
		'%s %s',
		$php_version_debug,
		( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
	);

	if ( $php64bit ) {
		$php_version_debug .= ' 64bit';
	}

	$fields = array();

	$fields['server_architecture'] = array(
		'label' => __( 'Server architecture' ),
		'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture' ) ),
		'debug' => $server_architecture,
	);
	$fields['httpd_software']      = array(
		'label' => __( 'Web server' ),
		'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
		'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
	);
	$fields['php_version']         = array(
		'label' => __( 'PHP version' ),
		'value' => $php_version,
		'debug' => $php_version_debug,
	);
	$fields['php_sapi']            = array(
		'label' => __( 'PHP SAPI' ),
		'value' => PHP_SAPI,
		'debug' => PHP_SAPI,
	);

	// Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
	if ( ! function_exists( 'ini_get' ) ) {
		$fields['ini_get'] = array(
			'label' => __( 'Server settings' ),
			'value' => sprintf(
			/* translators: %s: ini_get() */
				__( 'Unable to determine some settings, as the %s function has been disabled.' ),
				'ini_get()'
			),
			'debug' => 'ini_get() is disabled',
		);
	} else {
		$fields['max_input_variables'] = array(
			'label' => __( 'PHP max input variables' ),
			'value' => ini_get( 'max_input_vars' ),
		);
		$fields['time_limit']          = array(
			'label' => __( 'PHP time limit' ),
			'value' => ini_get( 'max_execution_time' ),
		);

		if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
			$fields['memory_limit']       = array(
				'label' => __( 'PHP memory limit' ),
				'value' => WP_Site_Health::get_instance()->php_memory_limit,
			);
			$fields['admin_memory_limit'] = array(
				'label' => __( 'PHP memory limit (only for admin screens)' ),
				'value' => ini_get( 'memory_limit' ),
			);
		} else {
			$fields['memory_limit'] = array(
				'label' => __( 'PHP memory limit' ),
				'value' => ini_get( 'memory_limit' ),
			);
		}

		$fields['max_input_time']      = array(
			'label' => __( 'Max input time' ),
			'value' => ini_get( 'max_input_time' ),
		);
		$fields['upload_max_filesize'] = array(
			'label' => __( 'Upload max filesize' ),
			'value' => ini_get( 'upload_max_filesize' ),
		);
		$fields['php_post_max_size']   = array(
			'label' => __( 'PHP post max size' ),
			'value' => ini_get( 'post_max_size' ),
		);
	}

	if ( function_exists( 'curl_version' ) ) {
		$curl = curl_version();

		$fields['curl_version'] = array(
			'label' => __( 'cURL version' ),
			'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
		);
	} else {
		$fields['curl_version'] = array(
			'label' => __( 'cURL version' ),
			'value' => __( 'Not available' ),
			'debug' => 'not available',
		);
	}

	// SUHOSIN.
	$suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );

	$fields['suhosin'] = array(
		'label' => __( 'Is SUHOSIN installed?' ),
		'value' => ( $suhosin_loaded ? __( 'Yes' ) : __( 'No' ) ),
		'debug' => $suhosin_loaded,
	);

	// Imagick.
	$imagick_loaded = extension_loaded( 'imagick' );

	$fields['imagick_availability'] = array(
		'label' => __( 'Is the Imagick library available?' ),
		'value' => ( $imagick_loaded ? __( 'Yes' ) : __( 'No' ) ),
		'debug' => $imagick_loaded,
	);

	// Pretty permalinks.
	$pretty_permalinks_supported = got_url_rewrite();

	$fields['pretty_permalinks'] = array(
		'label' => __( 'Are pretty permalinks supported?' ),
		'value' => ( $pretty_permalinks_supported ? __( 'Yes' ) : __( 'No' ) ),
		'debug' => $pretty_permalinks_supported,
	);

	// Check if a .htaccess file exists.
	if ( is_file( ABSPATH . '.htaccess' ) ) {
		// If the file exists, grab the content of it.
		$htaccess_content = file_get_contents( ABSPATH . '.htaccess' );

		// Filter away the core WordPress rules.
		$filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
		$filtered_htaccess_content = ! empty( $filtered_htaccess_content );

		if ( $filtered_htaccess_content ) {
			/* translators: %s: .htaccess */
			$htaccess_rules_string = sprintf( __( 'Custom rules have been added to your %s file.' ), '.htaccess' );
		} else {
			/* translators: %s: .htaccess */
			$htaccess_rules_string = sprintf( __( 'Your %s file contains only core WordPress features.' ), '.htaccess' );
		}

		$fields['htaccess_extra_rules'] = array(
			'label' => __( '.htaccess rules' ),
			'value' => $htaccess_rules_string,
			'debug' => $filtered_htaccess_content,
		);
	}

	// Check if a robots.txt file exists.
	if ( is_file( ABSPATH . 'robots.txt' ) ) {
		// If the file exists, turn debug info to true.
		$robotstxt_debug = true;

		/* translators: %s: robots.txt */
		$robotstxt_string = sprintf( __( 'There is a static %s file in your installation folder. WordPress cannot dynamically serve one.' ), 'robots.txt' );
	} elseif ( got_url_rewrite() ) {
		// No robots.txt file available and rewrite rules in place, turn debug info to false.
		$robotstxt_debug = false;

		/* translators: %s: robots.txt */
		$robotstxt_string = sprintf( __( 'Your site is using the dynamic %s file which is generated by WordPress.' ), 'robots.txt' );
	} else {
		// No robots.txt file, but without rewrite rules WP can't serve one.
		$robotstxt_debug = true;

		/* translators: %s: robots.txt */
		$robotstxt_string = sprintf( __( 'WordPress cannot dynamically serve a %s file due to a lack of rewrite rule support' ), 'robots.txt' );

	}

	$fields['static_robotstxt_file'] = array(
		'label' => __( 'robots.txt' ),
		'value' => $robotstxt_string,
		'debug' => $robotstxt_debug,
	);

	// Server time.
	$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );

	$fields['current']     = array(
		'label' => __( 'Current time' ),
		'value' => $date->format( DateTime::ATOM ),
	);
	$fields['utc-time']    = array(
		'label' => __( 'Current UTC time' ),
		'value' => $date->format( DateTime::RFC850 ),
	);
	$fields['server-time'] = array(
		'label' => __( 'Current Server time' ),
		'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ),
	);

	return array(
		'label'       => __( 'Server' ),
		'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host’s assistance.' ),
		'fields'      => $fields,
	);
}