函式名稱:opcache_get_configuration()
適用版本:PHP 5 >= 5.5.0, PHP 7, PHP 8
函式描述:opcache_get_configuration() 函式用於獲取當前的 OPcache 配置資訊。
用法:
opcache_get_configuration(): array|false
引數:
該函式不接受任何引數。
返回值:
- 如果成功,返回一個包含當前 OPcache 配置資訊的關聯陣列。
- 如果失敗,返回 false。
示例:
$config = opcache_get_configuration();
if ($config === false) {
echo "獲取配置資訊失敗!";
} else {
echo "OPcache 配置資訊如下:\n";
foreach ($config['directives'] as $directive) {
echo $directive['name'] . ": " . $directive['value'] . "\n";
}
}
上述示例中,我們首先使用 opcache_get_configuration() 函式獲取當前的 OPcache 配置資訊。然後,我們檢查返回值是否為 false,如果是,則表示獲取失敗。如果不是 false,我們遍歷關聯陣列的 directives 鍵,輸出每個指令的名稱和值。這樣就可以獲取並展示 OPcache 的配置資訊了。
注意:為了使用 opcache_get_configuration() 函式,你需要在 PHP 的配置檔案(php.ini)中啟用 OPcache 擴充套件。