In order to flush ouput to the browser, we need to use both ob_flush() and flush() (Apache 2, windows xp, php 5.2.6). When someone cancels loading of a php page (e.g. back button) Apache should not terminate the script. However, we find that if the script has both ob_flush() and flush() calls, it will get terminated. I'm not sure if it's Apache or php that's doing the terminating. I'm able to replicate this with Apache2 and php 5.2.6 on OS X Leopard as well. Below is a simple script that reproduces the problem. If you hit the script and then back button, the script only write the first output file and then terminate. Take out either the ob_flush() or the flush() and the script will run through as it should:
Code: Select all
<?php
$i = 0;
while($i < 4)
{
sleep(4);
echo $i;
$handle = fopen('/tmp/out'.$i.'.txt','w');
fwrite($handle,'1');
fclose($handle);
ob_flush();
flush();
$i++;
}
?>