PHP脚本处理:输出缓冲的地方? [英] PHP script processing: is output buffered somewhere?

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

问题描述

有人能向我解释PHP如何工作的?
假设我们有一个code是这样的:

Could someone explain to me how PHP really works? Suppose we have a code like this:

<?php
echo "line1 <br />";
echo "line2 <br />";
setcookie("TestCookie", "test");
echo "line3 <br />";
echo "line4 <br />";

时发送到客户端(浏览器)作为帧间preTER脚本处理它&ndash的;逐行所以
浏览器接收一号线第一,使得它,然后在2号线,使得它等等?抑或是所有脚本的输出缓冲的地方送一次全部脚本处理之后?

Is the script sent to the client (browser) as the interpreter processes it – line by line so the browser receives "line1" first, renders it, then "line2", renders it and so on? Or is all the script's output buffered somewhere and sent all at once after the script is processed?

推荐答案

尽管PHP按顺序执行的每一行,输出一般是缓冲的。

While PHP executes each line in order, output generally is buffered.

在PHP echo语句直接将输出发送到Web服务器或后端一个用户空间输出缓冲区。输出缓冲器的尺寸变化,可堆叠在其它输出缓冲器的顶部,和用于实现过滤器,如 gzip的COM pression

The PHP echo statement either sends output directly to the web server backend or to a "userspace" output buffer. Output buffers can vary in size, can be stacked on top of other output buffers, and are used to implement filters such as gzip compression.


  • 用户空间输出缓冲可以通过PHP code启用 和/或由PHP配置(INI)文件。您code被写入的方式,它实际上是必要的,因为PHP只能发送响应头,包括设置Cookie头,的响应体之前。 存在添加,获取的内容,并删除用户空间输出缓冲器各种功能。

  • Userspace output buffering can be enabled by PHP code and/or by the PHP configuration (INI) file. The way your code is written, it is actually necessary because PHP can only send response headers, including Set-Cookie headers, before the response body. Various functions exist to add, get the contents of, and remove userspace output buffers.

web服务器后端还可以结合自身的缓冲;刷新该缓冲区,调用冲洗()是必要的,除非的 ob_implicit_flush()是生成输出之前调用。尽管它的名字,ob_implicit_flush()做的的用户空间刷新缓冲区。

The web server backend may also incorporate its own buffering; to flush that buffer, calling flush() is necessary unless ob_implicit_flush() is called before generating output. Despite its name, ob_implicit_flush() does not flush userspace buffers.

这两种输出缓冲器的性能方面的原因存在,但不应该被禁用了一个很好的理由(例如的需要进行实时输出)。

Both kinds of output buffers exist for performance reasons and should not be disabled except for a very good reason (e.g. you need to perform realtime output).

这篇关于PHP脚本处理:输出缓冲的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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