将输出缓冲的用例作为对“已发送的报头"的正确解决方案. [英] Use case for output buffering as the correct solution to "headers already sent"

查看:60
本文介绍了将输出缓冲的用例作为对“已发送的报头"的正确解决方案.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(不仅在此站点上)看到很多经验不足的PHP程序员关于臭名昭著的已发送标题...输出始于"错误的许多问题,许多人建议使用输出缓冲作为解决方案.

I see (not just on this site) a lot of question from inexperienced PHP programmers about the infamous "headers already sent... output started at" error, and many people suggest using ouput buffering as a solution.

根据我的经验,我从未发现这种错误不是由程序逻辑缺陷引起的.在某些情况下,输出缓冲实际上是正确的解决方案吗?

In my experience I have never found a situation where that error wasn't caused by a flaw in the program's logic. Are there cases where output buffering is actually the correct solution?

推荐答案

我同意您的初稿.通常,使用输出缓冲解决标头"问题是权宜之计.

I would concur with your initial statement. Generally, solving "headers" problem with output buffering is a stopgap measure.

该解决方案真正令人难过/有趣的部分是:当您要输出较大的内容(例如您保留在付费专区中的文件)时会发生什么?通常,这会导致人们用脚本用完内存来替换标头"问题.

The really sad/funny part of this solution is: what happens when you want to output something large, such as a file you are keeping behind a paywall? Usually it results in people replacing the "headers" problem with their scripts running out of memory.

哇.

这篇关于将输出缓冲的用例作为对“已发送的报头"的正确解决方案.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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