PHP输出缓冲-听起来像个坏主意,对吗? [英] PHP output buffering - sounds like a bad idea, is it?

查看:79
本文介绍了PHP输出缓冲-听起来像个坏主意,对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只想在php输出缓冲方面吸引专家的注意.有时候,我出于某种原因想要实现它,但是总是设法重新排列我的代码以解决它.

Just want to pick the experts' brains on php output buffering. There are times when I've wanted to implement it for one reason or another, but have always managed to rearrange my code to get around it.

我避免使用它,因为这听起来会浪费资源.我的意思是,如果他们可以为编码器提供如此出色的灵活性,为什么他们不总是缓冲输出?我唯一能想到的答案是:因为不进行缓冲可以节省大量资源,并且通过良好的编码习惯,您不需要它.

I avoid using it because it sounds like it'll cost resources. I mean, if they can offer the coder such wonderful flexibility, why don't they always buffer output? The only answer I can come up with is: because not buffering it saves tremendous resources, and with good coding practice you shouldn't need it.

我要离开这里吗?

推荐答案

根据我的经验,对性能没有重大影响.我也无法在这个问题上找到一致的答案-有些人声称对性能几乎没有任何影响,而有些人则说效果很小但是很重要.甚至在php.net上也有一条评论建议,与多个输出函数相比,缓冲提高性能,而不是我已经验证了这一点或任何东西.

From my experience, there isn't a significant impact on performance. I also can't find consistent answers on the subject -- some people claim that there is barely any hit against performance, while some say that there is a minor but significant effect. There is even a comment on php.net suggesting that buffering increases performance as compared to multiple output functions, not that I've verified that or anything.

我认为是否要缓冲的问题与您的应用程序的预期用途有关.如果要在发送之前压缩输出,或者想要精确控制输出在代码中何时何地发生,缓冲就很有意义.由于添加缓冲并不需要花费太多精力,因此您不妨尝试一下-如果需要的话,删除它应该相对容易.

I think the question of whether or not to buffer has more to do with the intended use of your application. Buffering makes a lot of sense if you want to compress the output before sending it, or if you want to control exactly when and where the output takes place in your code. Since it doesn't take that much effort to add buffering, you may as well try it out -- it should be relatively easy to remove it if you need to.

这篇关于PHP输出缓冲-听起来像个坏主意,对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆