函数名称:opcache_get_status()
函数描述:opcache_get_status() 函数用于获取 OPCache 缓存的状态信息。
适用版本:PHP 5 >= 5.5.5, PHP 7, PHP 8
语法:opcache_get_status(bool $get_scripts = true): array|false
参数:
返回值:
示例:
<?php
$status = opcache_get_status();
if ($status !== false) {
echo "OPCache 缓存已启用\n";
echo "版本号:" . $status["version"]["version"] . "\n";
echo "内存使用情况:" . round($status["memory_usage"]["used_memory"] / 1024 / 1024, 2) . "MB / " . round($status["memory_usage"]["free_memory"] / 1024 / 1024, 2) . "MB\n";
echo "已缓存的脚本数量:" . $status["opcache_statistics"]["num_cached_scripts"] . "\n";
echo "缓存命中率:" . round($status["opcache_statistics"]["opcache_hit_rate"], 2) . "%\n";
} else {
echo "OPCache 缓存未启用\n";
}
?>
解释:
注意事项: