ob_get_level() 从级别 1 开始
输出缓冲存在一些问题。主要是,我尝试使用 ob_gzhandler 回调运行输出缓冲,但它一直告诉我它使用了不受支持的压缩类型。一切都已启用,我相信问题是在脚本开头运行 ob_get_level() 会产生级别 1。php.ini 将我的 output_buffering 设置为 4096。
如果我运行类似以下内容:
while(ob_get_level() > 0){
ob_end_clean();
}
那么我可以成功运行 ob_start( )与 ob_gzhandler 回调。但我想知道这是否应该成为一个问题。在我的脚本中,我在不同的点调用 ob_clean() ,因为我避免堆叠太多缓冲区,因为我读到这可以提高性能。我只是不确定我应该在这里做什么。
干杯。
Having a few problems with output buffering. Mainly, I'm trying to run output buffering with the ob_gzhandler callback, but it keeps telling me its using an unsupported compression type. Everything is enabled, and I believe the problem is that running ob_get_level() at the start of my script produces a level of 1. php.ini has my output_buffering set to 4096.
If I run something like:
while(ob_get_level() > 0){
ob_end_clean();
}
Then I can successfully run ob_start() with the ob_gzhandler callback. But I'm wondering if it should be a problem. During my script I make calls to ob_clean() at various points as I'm avoiding stacking too many buffers as I've read this can increase performance. I'm just unsure as to what I should be doing here.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下启用输出缓冲(请参阅文档) - 基本上意味着每个 PHP 脚本都以 ob_start() 开头。
如果您想禁用所有 PHP 脚本的默认 OB,请在 php.ini 中设置
output_buffering = Off
。如果您只想禁用此特定脚本的默认 OB,请使用
while
循环 - 这是非常正确的。至于 ob_clean - 您确定要删除缓冲区中的输出?在我看来,这并不是真正必要的,除非您发现页面加载速度非常慢。不要担心优化(至少现在不是)。
You have output buffering enabled by default (see the docs) - that basically means that every PHP script starts with ob_start().
If you want to disable the default OB for all PHP scripts, in your php.ini, set
output_buffering = Off
.If you only want to disable the default OB for this specific script, use the
while
loop - it's quite correct.As for the ob_clean - are you sure you want to delete the output that's in your buffer? IMO it's not really necessary, unless you are seeing significant slow page loads. Don't worry about optimizing that (at least not now).