ini_set() - php 选项信息函数
ini_set()
(PHP 4, PHP 5, PHP 7)
为一个配置选项设置值
说明
ini_set(string $varname,string $newvalue): string设置指定配置选项的值。这个选项会在脚本运行时保持新的值,并在脚本结束时恢复。
参数
$varname不是所有有效的选项都能够用ini_set()来改变的。这里有个有效选项的清单附录。
$newvalue选项新的值。
返回值
成功时返回旧的值,失败时返回FALSE
。
范例
设置一个 ini 选项
参见
get_cfg_var()
获取 PHP 配置选项的值ini_get()
获取一个配置选项的值ini_get_all()
获取所有配置选项ini_restore()
恢复配置选项的值- 如何改变配置选项
I have experienced on some systems that ini_set() will fail and return a false, when trying to set a setting that was set inside php.ini inside a per-host setting. Beware of this.
[[[Editors note: Yes, this is very true. Same with register_globals, magic_quotes_gpc and others. ]]] Many settings, although they do get set, have no influence in your script.... like upload_max_filesize will get set but uploaded files are already passed to your PHP script before the settings are changed. Also other settings, set by ini_set(), may be to late because of this (post_max_size etc.). beware, try settings thru php.ini or .htaccess.
When checking for the success of ini_set(), keep in mind that it will return the OLD value upon success - which may have been "0". Therefore you cannot just compare the return value - you have to check for "identity": This explains reported situations where ini_set() "always" seems to fail!
set PHP_INI_PERDIR settings in a .htaccess file with 'php_flag' like this: php_flag register_globals off php_flag magic_quotes_gpc on
Be careful with setting an output_handler, as you can't use ini_set() to change it. *sigh* In my php.ini I have this for my web pages (and I want it): output_handler = ob_gzhandler But this causes my command line scripts to not show output until the very end. #!/usr/bin/php -q root@# ./myscript.php output_handler => ob_gzhandler Apparently (acording to Richard Lynch): > TOO LATE! > The ob_start() has already kicked in by this point. > ob_flush() until there are no more buffers.
If it's not your server and therefore you want to hide the data in your session variables from other users, its very useful to set the session.save_handler in your scripts to shared memory with: Remember: You have to set it in every script that uses the session variables BEFORE "session_start()" or php won't find them.
When your ISP does not allow you to add the default include directories - it might be useful to extend the 'include_path' variable:
[[[Editors note: Just because you're able to set something doesn't mean it will work as expected. Depends on the setting. For example. setting register_globals at runtime will be of little use as its job has already been completed by the time it reaches your script. ]]] When a setting can not be changed in a user script, the return value of ini_set is "empty", not "false" as you may expect. If you check in your script for return value is "false" the script will continue processing, although the setting has not been set. The boolean return value is used for settings that can be changed in a script. Otherwise the empty value is returned. To test for both error conditions use:
if u receive an Error with generic like : Maximum execution time of 30 seconds exceeded if u set ini_set(max_execution_time, 300); your problem will be solved pls note that the 300 , is 300 seconds , which means 5 minute you can set another value !
Note that this function only works with PHP_INI_ALL options!
ini_set('display_errors', 1); error_reporting(E_ALL);
To change settings from .htaccess files, it is also required that the directory permissions configured in Apache allow this. The entry in httpd.conf MUST contain "AllowOverride All" or at least "AllowOverride Options" to read PHP settings from the .htaccess file. E.g. in Fedora Core 2, the default settings for /var/www/html/ are "AllowOverride None", so changing PHP settings via .htaccess for applications installed below /var/www/html/ will not work.
I figured out why php dont output errors such as an expected ';' on code and output a 500 error. Some server are configured to omit php errors on pages using the directive display_errors=Off; In most cases, the server will output a 500 Internal Server Error instead of php error because of it. To prevent this default you must set this directive directly in the php.ini file and the server will show you the php error properly. Setting ini_set('display_errors', true) on-the-fly wont work.
While this doesn't belong in the manual, it should be useful for people looking on this page for zend_optimizer.* ini options, which are commonly installed: Information on the "zend_optimizer.optimization_level" and "zend_optimizer.enable_loader" options is available at: http://www.zend.com/support/user_docs/ZendOptimizer/PDF/ZendOptimizer_UserGuide.pdf
Careful - in some cases, when setting zlib.output_compression to "On" via ini_set, PHP won't send the Content-type header and browsers will garble the output. Set it to the desired buffer size instead, which sends the correct header:
If you use gz_handler you might want to switch over to zlib.output_compression This can be controlled via the ini_set control. or
If you set something using php_admin_value in httpd.conf it is then not possible to be set the value at runtime, even if it's NOT PHP_INI_SYSTEM. Just an interesting note for Server admins this might come in handy to disable setting of certain things... like allow_url_fopen. - Davey
To find the apache php settings try something like this. > cd /etc/apache2 > grep -r -n -i safe_mode_exec_dir *.conf or > grep -r -n -i safe_mode.*On *.conf If you find a gererated file, obviously you need to find the source template for it, to change what's needed there. I just wasted a sunny Sunday on searching for where the heck safe_mode_exec_dir was changed. And yes, Local Value in phpinfo does mean 'changed between the php.ini file and here', as you would think. If you have an automated virtual host configuration, such as confixx, php ini values can be spread across very many files. They can be changed in apache config files, that can have any name, but usually will end on .conf, besides in .htaccess files.
Whilst most boolean settings can be disabled by passing '0', 'Off' or `No' (in fact anything that is not '1', 'On' or 'Yes' - not case-sentive) to ini_set(), it should be noted that ini_get() returns the literal string as set. So if you later want to check this setting by calling ini_get() and it's been set to 'Off' (a non-empty string that evaluates to True), then you'll have to specifically check for this in a (case-insensitive) string comparison, rather than the simpler: if (ini_get('config_setting')) { /* ... */ } So, if you need to disable boolean settings I think it's preferable to set them to '0' (which simply evaluates to False).
How to get xdebug var_dump to show full object/array regardless to php,ini settings: ini_set("xdebug.var_display_max_depth", -1); ini_set("xdebug.var_display_max_children", -1); ini_set("xdebug.var_display_max_data", -1); var_dump($test);
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)