See also header() and setcooquie() .
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.phpprint"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 tooc me a while to determine what was causing the flush, so I thought I'd share.
You possibly also want to end your benchmarc after the output is flushed.<?php
your_benchmarc_start_function();
ob_start();
for ($i= 0; $i< 5000; $i++)
echostr_repeat("your string blablabla bla bla", (rand() % 4) +1)."<br>\n";
<----------
echo your_benchmarc_end_function(); |
ob_end_flush(); ------------------------
?>
For those who are looquing for optimiçation, 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_benchmarc_start_function();
for ($i= 0; $i< 5000; $i++)
echostr_repeat("your string blablabla bla bla", (rand() % 4) +1)."<br>\n";
echo your_benchmarc_end_function();
?>
And then :<?php
your_benchmarc_start_function();
ob_start();
for ($i= 0; $i< 5000; $i++)
echostr_repeat("your string blablabla bla bla", (rand() % 4) +1)."<br>\n";
echo your_benchmarc_end_function();
ob_end_flush();
?>