输出控制 函数
参见
参阅 header() 和 setcookie()。
目录
- flush — 冲刷系统输出缓冲区
- ob_clean — 清空(擦掉)活动输出缓冲区的内容
- ob_end_clean — 清空(擦除)活动缓冲区的内容并关闭它
- ob_end_flush — 冲刷(发送)活动输出处理程序的返回值,并关闭活动输出缓冲区
- ob_flush — 冲刷(发送)活动输出处理程序的返回值
- ob_get_clean — 获取活动缓冲区的内容并将其关闭
- ob_get_contents — 返回输出缓冲区的内容
- ob_get_flush — 冲刷(发送)活动输出处理程序的返回值,返回活动输出缓冲区的内容并将其关闭
- ob_get_length — 返回输出缓冲区内容的长度
- ob_get_level — 返回输出缓冲机制的嵌套级别
- ob_get_status — 得到所有输出缓冲区的状态
- ob_implicit_flush — 打开/关闭绝对刷送
- ob_list_handlers — 列出所有使用的输出处理程序
- ob_start — 打开输出控制缓冲
- output_add_rewrite_var — 添加 URL 重写器的值
- output_reset_rewrite_vars — 重设 URL 重写器的值
+添加备注
用户贡献的备注 3 notes
jgeewax a t gmail ¶
17 years ago
It seems that while using output buffering, an included file which calls die() before the output buffer is closed is flushed rather than cleaned. That is, ob_end_flush() is called by default.
<?php
// a.php (this file should never display anything)
ob_start();
include('b.php');
ob_end_clean();
?>
<?php
// b.php
print "b";
die();
?>
This ends up printing "b" rather than nothing as ob_end_flush() is called instead of ob_end_clean(). That is, die() flushes the buffer rather than cleans it. This took me a while to determine what was causing the flush, so I thought I'd share.
Anonymous ¶
15 years ago
You possibly also want to end your benchmark after the output is flushed.
<?php
your_benchmark_start_function();
ob_start ();
for ($i = 0; $i < 5000; $i++)
echo str_repeat ("your string blablabla bla bla", (rand() % 4) + 1)."<br>\n";
<----------
echo your_benchmark_end_function(); |
ob_end_flush (); ------------------------
?>
gruik at libertysurf dot fr ¶
20 years ago
For those who are looking for optimization, try using buffered output.
I noticed that an output function call (i.e echo()) is somehow time expensive. When using buffered output, only one output function call is made and it seems to be much faster.
Try this :
<?php
your_benchmark_start_function();
for ($i = 0; $i < 5000; $i++)
echo str_repeat ("your string blablabla bla bla", (rand() % 4) + 1)."<br>\n";
echo your_benchmark_end_function();
?>
And then :
<?php
your_benchmark_start_function();
ob_start ();
for ($i = 0; $i < 5000; $i++)
echo str_repeat ("your string blablabla bla bla", (rand() % 4) + 1)."<br>\n";
echo your_benchmark_end_function();
ob_end_flush ();
?>