PHP的echo-ING内容页面加载 [英] PHP echo-ing content as page loads

查看:145
本文介绍了PHP的echo-ING内容页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我做了一些与PHP / Apache的实验。
比方说,我有这个code。

So I'm doing some experimenting with PHP/Apache. Let's say I have this code.

<div>DIV 1</div>
<?php sleep(2); ?>
<div>DIV 2</div>
<?php sleep(2); ?>
<div>DIV 3</div>
<?php sleep(2); ?>
<div>DIV 4</div>
<?php sleep(2); ?>

有关我的本地Apache网络服务器因故所有的数据出现在浏览器的一次,全部4睡眠()■已执行后(8秒)。

For some reason on my local apache webserver all the data appears in the browser at once, after all 4 sleep()s have been executed (8 seconds).

但是,如果我在我的主机的服务器上运行,数据是回声版实时浏览器。
作为... DIV1出现,2秒后格2出现等。

However if I run it on my host's server, the data is echo-ed to the browser in real time. As in... div1 appears, after 2 seconds div 2 appears etc.

这是为什么?这是Apache的一些设置?

Why is that? Is this some setting in Apache?

推荐答案

没有它可能是在PHP的设置。

No it may be a setting in php.

在你的本地服务器,output_buffering你的php.ini文件中启用。

In you local server, output_buffering is enabled in your php.ini file.

您可以通过设置将其禁用:

You can disable it by setting :

output_buffering = off

要确保内容是使用回声般的语句每次发送到浏览器中,添加:

To Ensure that the content is sent to the browser each time a echo-like statement is used, add :

implicit_flush = on

您还可以通过给output_buffering的值设置缓冲区的大小。

You also can set the buffer size by giving output_buffering a value.

output_buffering = 4096

在这里缓冲区大小是4KB。

here the buffer size would be 4KB.

输出缓冲告诉PHP将保存在内存中的所有数据将被发送到浏览器,直到它在你的code encouters冲洗()指令,缓冲区恰好是满,或者是脚本的结尾。

Output buffering tells php to keep in memory all data to be sent to the browser until it encouters a flush() instruction in your code, the buffer happens to be full, or it is the end of the script.

下面是从php.net输出缓冲器充分借鉴: PHP的输出缓冲

Here is the full reference for output buffer from php.net : php output buffer

这篇关于PHP的echo-ING内容页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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