2024 日本 PHP 研討會

apache_get_modules

(PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8)

apache_get_modules取得已載入 Apache 模組的列表

說明

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
)

新增註釋

使用者貢獻的註釋 4 則註釋

hello at octopuslabs dot io
4 年前
apache_get_modules() 僅在 PHP 以模組方式安裝而非 CGI 方式安裝時可用 == 它不適用於 php-fpm。
匿名
11 年前
<?php
function apache_module_exists($module)
{
return
in_array($module, apache_get_modules());
}
?>
Vlad Alexa Mancini mancini at nextcode dot org
19 年前
此函式可以在較舊的 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;
}

?>
christian at zp1 dot net
10 個月前
/**
* 檢查是否已載入 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;
}
}

To Top