php 中 get_cfg_var() 与 ini_get() 的异同
2014-10-31 19:52 brookin 阅读(436) 评论(0) 编辑 收藏 举报背景
get_cfg_var() 取的值是配置文件中的值
ini_get() Gets the value of a configuration option, 则取的当前值(运行时,PHP系统定义)
示例
<?php
print get_cfg_var('memory_limit'); // 返回 1024M
print("\n");
print ini_get('memory_limit'); // 返回 1024M
print("\n");
ini_set('memory_limit', '12M');
print ini_get('memory_limit'); // 返回 12M
print("\n");
print get_cfg_var('memory_limit'); // 返回 1024M
print("\n");
ini_restore('memory_limit');
print ini_get('memory_limit'); // 返回 1024M
print("\n");
print get_cfg_var('memory_limit'); // 返回 1024M
print get_cfg_var('memory_limit'); // 返回 1024M
print("\n");
print ini_get('memory_limit'); // 返回 1024M
print("\n");
ini_set('memory_limit', '12M');
print ini_get('memory_limit'); // 返回 12M
print("\n");
print get_cfg_var('memory_limit'); // 返回 1024M
print("\n");
ini_restore('memory_limit');
print ini_get('memory_limit'); // 返回 1024M
print("\n");
print get_cfg_var('memory_limit'); // 返回 1024M
Notes
The difference between get_cfg_var() and ini_get() is that the former returns whatever is in php.ini while the latter returns the runtime settings.
Configure the following parameter in php.ini.
[test_module]
test_module.name = "module_name"
test_module.name = "module_name"
get_cfg_var() will happily return the text(module_name) while ini_get() would not, as it's not configurable option belonging to any extension. Or, in another word, ini_get() will only return items that are defined in the source code.
作者:brookin
出处:http://www.cnblogs.com/brookin/
本文采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
出处:http://www.cnblogs.com/brookin/
本文采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。