在生产环境中我应该打开还是关闭output_buffering?
我即将启动一个网站,我将检查 php.ini 来准备生产环境的所有设置。
我正在争论是否将output_buffering保留为开、关,或者将其设置为缓冲区限制(如4096)。打开或关闭output_buffer有什么优点或缺点吗?我读到关闭缓冲区会给你带来一些额外的性能,但是在做出决定之前我应该知道什么?
为什么要关闭它?
为什么要保留它?
为什么要保留缓冲区限制?
I'm about to launch a website and I'm going over my php.ini to prepare all the settings for a production environment.
I'm debating whether to leave output_buffering On, Off, or set it to a buffer limit (like 4096). Is there any pro's or con's to having the output_buffer turned On or Off? I've read that turning the buffer Off will give you some extra performance, but is there anything I should know before making my decision?
Why leave it off?
Why leave it on?
Why leave it on with a buffer limit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输出缓冲最常见的用法实际上是允许您的脚本通过打印/回显等方式开始“写入”页面内容。但仍然允许稍后在脚本中调用 header() 来正常工作(因为标头只能在任何实际页面内容之前发送)。如果您的脚本使用这样的功能,那么您需要保留输出缓冲,以便您的脚本能够在所有 header() 调用正常运行的情况下继续运行。 (否则您将收到精彩的“header():警告,无法修改标头信息,标头已发送”消息。)
The most common usage of output buffering is actually to allow your scripts to begin "writing" page content via print/echo/etc. yet still allow header() calls later in the script to work properly (since headers can only be sent before any actual page content is). If your scripts make use of such, then you'll need to leave output buffering on in order for your scripts to continue functioning with all header() calls behaving properly. (Otherwise you'll get the wonderful "header(): Warning, could not modify header information, headers already sent" message.)
它是一个配置指令,与
register_globals
和magic_quotes_runtime
不同,因为它没有足够的争议来保证默认情况下将其关闭。让它保持启用状态,以防万一你需要它(这就是我要做的)。据我所知,无论如何这样做不会产生明显的安全漏洞。It's a configuration directive unlike
register_globals
andmagic_quotes_runtime
in that it's not controversial enough to warrant keeping it off by default. Leave it enabled, in case you ever need it (it's what I'd do). As far as I know, there's no glaring security hole that arises from doing so anyway.实际上,只有当您尝试存储否则总是会输出到屏幕的信息时,才需要 OB。例如,OB 适合存储包含文件的解析输出。
如果您不使用 OB 来处理这些类型的薄膜,那么还有其他更有效的方法可以实现,您应该在此处查询它们。
You really only need OB when you're trying to store information that would otherwise always be outputted to the screen. For example, OB is good for storing the parsed output from an included file.
If you're not using OB for those types of thins, then there are other, more efficient ways of going about it, and you should inquire about them here.