ini_set()的作用范围?
我有 index.php
和几个级联包含的文件,类似这样。
index.php -> controller.php -> model.php -> view.php
在 model.php
中,我有一个使用 ini_set('memory_limit', '-1');
的函数
ini_set()
设置更改是否过期?
执行index.php
后?或者view.php
?或者model.php
中的函数?
I've had index.php
and several files which cascading include,something like this.
index.php -> controller.php -> model.php -> view.php
In model.php
I have a function using ini_set('memory_limit', '-1');
When will the ini_set()
change of the setting expire?
After executed index.php
? Or view.php
? Or the function in model.php
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于整个一个请求,
ini_set()
对于脚本中发生的所有事情(不仅仅是当前文件:正在发生的整个执行线程)都是全局;无论您何时调用它,它都将始终影响此脚本的全局设置。当您的脚本终止时,效果将过期 - 例如通过exit
、die
或运行到index.php
末尾。它不会影响任何其他同时运行的脚本(那些需要自己调用
ini_set
的脚本),并且不会保留到以后的请求中(如果需要持久设置,则需要编辑php.ini )。
请注意,文档说了同样的事情:
编辑:由于显然不清楚:您使用 ini_set 更改的值将对整个脚本有效。当前执行在哪里(在哪个文件中、在哪个类中、在哪个函数中)并不重要;任何地方的设置都是一样的。它将保持这种状态,直到您再次更改它,或者直到整个脚本终止。 (不是当前文件,不是当前函数;整个脚本)
ini_set()
is global for everything that happens in the script (not just the current file: the whole thread of execution that is occurring), for this entire one request; it doesn't matter whence you invoke it, it will always affect the global settings for this script. The effect will expire when your script terminates - e.g. throughexit
,die
, or running off the end ofindex.php
.It will not affect any other scripts running simultaneously (those need to call
ini_set
themselves), and it will not persist into later requests (if you need persistent settings, you need to editphp.ini
).Note that the documentation says the same thing:
Edit: Since it is apparently unclear: the value you change using
ini_set
will be valid for the whole script onwards. It doesn't matter where the execution currently is (in what file, in what class, in what function); the setting will be the same, everywhere. It will remain so until you change it again, or until the whole script terminates. (not the current file, not the current function; the whole script)