什么是输出缓冲? [英] What is output buffering?

查看:142
本文介绍了什么是输出缓冲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是输出缓冲?为什么要在PHP中使用它?

What is output buffering and why is one using it in PHP?

推荐答案

没有输出缓冲(默认),您的HTML作为PHP进程通过脚本逐段发送到浏览器.使用输出缓冲,您的HTML存储在一个变量中,并在脚本末尾作为一个片段发送到浏览器.

Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script.

为Web开发人员提供输出缓冲的优势

Advantages of output buffering for Web developers

  • 单独打开输出缓冲可减少下载和呈现HTML所需的时间,因为在PHP处理HTML时不会将其分段发送给浏览器.
  • 我们可以使用PHP字符串完成所有花哨的工作,现在我们可以将整个HTML页面作为一个变量来处理.
  • 如果在设置Cookie时遇到过警告:无法修改标题信息-标题已由(输出)发送的标题"消息,您将很高兴知道输出缓冲是您的答案.
  • Turning on output buffering alone decreases the amount of time it takes to download and render our HTML because it's not being sent to the browser in pieces as PHP processes the HTML.
  • All the fancy stuff we can do with PHP strings, we can now do with our whole HTML page as one variable.
  • If you've ever encountered the message "Warning: Cannot modify header information - headers already sent by (output)" while setting cookies, you'll be happy to know that output buffering is your answer.

这篇关于什么是输出缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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