【发布时间】:2020-01-18 00:30:50
【问题描述】:
我想知道如何检查 PHP 中的配置选项是否已更改。
目前我正在使用ini_get_all(),它几乎可以工作:
// Change the error_log directive
ini_set('error_log', '/tmp/php.log');
$settings = array_filter(ini_get_all(), function ($item) {
return ($item['access'] !== INI_SYSTEM);
});
foreach ($settings as $key => $value) {
if ($value['local_value'] !== $value['global_value']) {
echo $key . ' is modified<br />';
}
}
但是,当一个选项的默认值未在配置文件中设置时,local_value 和 global_value 在被覆盖时似乎将设置为相同的值。查看phpinfo(),这些设置的主值显示为no value。
我也尝试使用get_cfg_var(),但没有按我的意愿使用:
// Change the error_log directive
ini_set('error_log', '/tmp/php.log');
$settings = array_filter(ini_get_all(), function ($item) {
return ($item['access'] !== INI_SYSTEM);
});
foreach ($settings as $key => $value) {
if (get_cfg_var($key) !== $value['local_value']) {
echo $key . ' is modified<br />';
}
}
【问题讨论】:
-
$item['access'] !== INI_SYSTEM对我来说毫无意义,这不是对所有事情都适用吗?将其更改为$item['global_value'] !== $item['local_value'];似乎对我有用,它会显示 error_log 已修改 -
@zanderwar - 我使用
ini_get_all()获取所有配置选项,然后使用array_filter()删除只能在php.ini文件中设置的项目。我不使用它来检查值是否已被修改?另外,如果您阅读了我的问题,我清楚地说明它适用于默认配置中 are 设置(非空)的值,所以我的猜测是您的php.ini中有一个设置为error_log。对phpinfo()报告为no value的设置尝试相同的设置,您就会明白我的意思了。
标签: php configuration settings configuration-files ini