PHP is handing the data to apache, but you still have to deal with apache buffer, apache will only accept a set amount from php when thats full php must wait for it to be cleared, remember echo is not a php function its a php method!
Okay heres a very simple script that may help me explain.
Basically this either output to apache or doesn't all depending on ob_start()
So with ob_start("callback"); being used PHP doesn't ever get told to send to the browser (well infact doesn't get told to send to apache!)
without it.. well it's like normal..
So your expect the times to be the same.. considering its the same code and all!
Well No..Echo doesn't get to apache and thus theirs no delays..
i run this on my PC and the times are as below
//Time:6.8108780384064 //Via Apache
//Time:0.067671060562134 //Via PHP ONLY
<?php
function callback($buffer)
{
global $echobuffer;
$echobuffer .= $buffer;
return "";
}
function test($WithApache = false,$file)
{
global $echobuffer;
$echobuffer ="";
if(!$WithApache)ob_start("callback"); //Don't pass to apache
$c=0;
$begin = microtime(true);
while($c<10000)
{
$c++;
echo rand(1111111111,9999999999)."<br>";
ob_flush();
flush();
}
ob_end_flush();
$end = microtime(true);
$time = "Time:".($end-$begin)."<br>\n";
file_put_contents($file,"$time $echobuffer");
echo $time;
}
test(false,"c:/test1.txt");
test(true,"c:/test2.txt");
?>
i increased the loop to 100000 and the times are as follows
//timesout (after 30 seconds) //Via Apache
//Time:0.67965197563171 //Via PHP ONLY
Now if i change the code to do just 1 echo..
ie
function test2($WithApache = false,$file)
{
global $echobuffer;
$echobuffer ="";
if(!$WithApache)ob_start("callback"); //Don't pass to apache
$c=0;
$begin = microtime(true);
$str = "";
while($c<100000)
{
$c++;
$str .= rand(1111111111,9999999999)."<br>";
ob_flush();
flush();
}
echo $str;
ob_end_flush();
$end = microtime(true);
$time = "Time:".($end-$begin)."<br>\n";
file_put_contents($file,"$time $echobuffer");
echo $time;
}
heres the times
Time:0.80782103538513 //Via Apache
Time:0.75758194923401 //Via PHP ONLY
BUT! the page took 44 Seconds to load
So the reason their was no timeout was because PHP had infact finished (BUT apache still had work todo)..
Okay well i have to go eat.. i hope that helps explain a little better..
But to do believe this is more of a apache issule!
--MadTechie
