php 4 和 5 之间的输出有区别吗?
前几天我注意到我为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许 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.我怀疑 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)数据何时发送取决于 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()
andob_end_flush()
to take control of the buffer. The Zend Framework does some clever stuff with output buffering for instance...通常的嫌疑人是:
仔细看看 phpinfo() 工具看看HTTP 标头可以帮助您。
The usual suspects are:
A close look at phpinfo() at a tool to see HTTP headers can help you.