php 4 和 5 之间的输出有区别吗?

发布于 2024-08-15 23:11:52 字数 157 浏览 6 评论 0原文

前几天我注意到我为 php 5 编写的一个新脚本开始输出 html,在 php 脚本实际完成之前就可以查看该 html。 4 也出现过这种情况吗?

例如,我有一个很长的循环,每次迭代都会回显一些内容。输出的 kb 很小,所以我不认为它是由于下载速度而延迟的。有人可以解释输出的差异吗?

I noticed the other day that a new script I wrote for php 5 began outputting html that was viewable before the php script had actually finished. Did this happen with 4?

For instance, I have a long loop that echos something out with each iteration. The output was small in terms of kb, so I dont think it was lag due to the download speed. Can someone explain the difference in output?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最偏执的依靠 2024-08-22 23:11:52

也许 output_buffering 的配置有所不同指令,在 php.ini 中?

如果启用了 output_buffering,PHP 会将生成的输出“保留”在内存中(至少,如果它不大于内存缓冲区的大小),并且仅当页面生成完成后才将其发送到浏览器。

如果禁用output_buffering,则即使脚本的执行尚未完成,输出也会在生成后立即发送。

Maybe there a difference in the configuration of the output_buffering directive, in php.ini ?

If output_buffering is enabled, PHP will "keep" the generated output in memory (at least, if it doesn't become bigger than the size of the memory buffer), and only send it to the browser when the page's generation is finished.

If output_buffering is disabled, the ouput is sent immediatly when generated, even if the script's execution is not finished yet.

网白 2024-08-22 23:11:52

我怀疑 PHP 4 和 5 之间在这方面存在差异,但您可以在两个版本上获得此行为,即通过启用/禁用 output_buffer。也许 PHP 5 的默认值与 PHP 4 的默认值不同? (没查过)

I doubt there is a difference to this regard between PHP 4 and 5, but you can get this behaviour on both versions, namely by enabling/disabling the output_buffer. Maybe the default value for PHP 5 is different than it was for PHP 4? (Haven't checked)

街角迷惘 2024-08-22 23:11:52

数据何时发送取决于 PHP 配置,它是一个输出缓冲区,并且行为类似于缓冲区。

话虽如此,您可以使用函数 ob_start()ob_end_flush() 来控制缓冲区。 Zend 框架在输出缓冲方面做了一些聪明的事情,例如......

When the data is sent, is dependant on PHP configuration, it's an output buffer, and behaves like a buffer.

Having said that, you can use the function ob_start() and ob_end_flush() to take control of the buffer. The Zend Framework does some clever stuff with output buffering for instance...

沉鱼一梦 2024-08-22 23:11:52

通常的嫌疑人是:

仔细看看 phpinfo() 工具看看HTTP 标头可以帮助您。

The usual suspects are:

A close look at phpinfo() at a tool to see HTTP headers can help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文