apache_get_modules() 僅在 PHP 以模組方式安裝而非 CGI 方式安裝時可用 == 它不適用於 php-fpm。
(PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8)
apache_get_modules — 取得已載入 Apache 模組的列表
此函式沒有參數。
已載入的 Apache 模組陣列。
範例 #1 apache_get_modules() 範例
<?php
print_r(apache_get_modules());
?>
上述範例將輸出類似以下的內容:
Array ( [0] => core [1] => http_core [2] => mod_so [3] => sapi_apache2 [4] => mod_mime [5] => mod_rewrite )
apache_get_modules() 僅在 PHP 以模組方式安裝而非 CGI 方式安裝時可用 == 它不適用於 php-fpm。
<?php
function apache_module_exists($module)
{
return in_array($module, apache_get_modules());
}
?>
此函式可以在較舊的 PHP 版本上使用,方法是將 "/etc/httpd/httpd.conf" 之類的路徑作為 $fname 參數。
<?php
function get_modules ($fname){
if (is_readable($fname)){
$fcont = file($fname);
if (is_array($fcont)){
foreach ($fcont as $line){
if (preg_match ("/^LoadModule\s*(\S*)\s*(\S*)/i",$line,$match)){
$return[$match[2]] = $match[1];
}
}
}
}
return $return;
}
?>
/**
* 檢查是否已載入 Apache 模組(即使 php 以 fcgi 或 cgi 方式執行)
*
* @param string $module
* @return bool
*/
public static function apache_check_module(string $module): bool
{
$module = ($module ? strval(value: $module) : '');
if (function_exists('apache_get_modules') && !empty($module)) {
if (in_array(needle: $module, haystack: apache_get_modules())) {
return TRUE;
}
} 否則,如果 (!empty(shell_exec(指令: 'apache2ctl -M | grep \'' . $module . '\''))) {
return TRUE;
}
否則 {
傳回 FALSE;
}
}