wppaste
WordPress

apache_mod_loaded( string $mod, bool $default_value = false ): bool

Since
2.5.0
Source
wp-includes/functions.php:6288
Determines whether the specified module exist in the Apache config.

Compatibility

WordPress
since 2.5.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.

Parameters

$modstring
The module, e.g. mod_rewrite.
$default_valuebooloptional
The default return value if the module is not found. Default false.Default: false

Return value

bool
Whether the specified module is loaded.

Performance profile

How much work a call to apache_mod_loaded() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
5–28

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

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

What one call costs · 5 distinct outcomes

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

WhenInstructionsCalls it makes
always5none
!function_exists() && !empty($loaded_mods)12function_exists()
function_exists()16–18function_exists(), apache_get_modules()
!function_exists() && empty($loaded_mods)22function_exists(), ob_start(), phpinfo(), ob_get_clean()
function_exists() && !$mod && empty($loaded_mods)28function_exists(), apache_get_modules(), ob_start(), phpinfo(), ob_get_clean()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev315–285
8.5315–285
8.4315–2856 fewer instructions than PHP 8.3
8.3375–345
8.2375–345
8.1375–3456 fewer instructions than PHP 7.4
7.4435–406

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

  • str_contains()Polyfill for `str_contains()` function added in PHP 8.0.

Used by · 2

Source code

function apache_mod_loaded( $mod, $default_value = false ) {	global $is_apache; 	if ( ! $is_apache ) {		return false;	} 	$loaded_mods = array(); 	if ( function_exists( 'apache_get_modules' ) ) {		$loaded_mods = apache_get_modules(); 		if ( in_array( $mod, $loaded_mods, true ) ) {			return true;		}	} 	if ( empty( $loaded_mods )		&& function_exists( 'phpinfo' )		&& ! str_contains( ini_get( 'disable_functions' ), 'phpinfo' )	) {		ob_start();		phpinfo( INFO_MODULES );		$phpinfo = ob_get_clean(); 		if ( str_contains( $phpinfo, $mod ) ) {			return true;		}	} 	return $default_value;}

Changelog

Introduced in 2.5.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-includes/functions.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.