While flush()
, ob_end_flush()
and ob_flush()
is supposed to guarantee that output is sent to the server, I've found that PHP is sometimes not very forgiving of particular software configuration.
On Windows especially, output buffering can be a pain to setup and the only way I've found that works reliably between systems is to reset output buffering on every flush like so:
<?php
obf_start();
for($i=0;$i<70;$i++) {
echo 'printing... ', microtime(true), '<br />';
if($i % 3 == 2) obf_flush();
usleep(300000);
}
function obf_start() {
ob_start();
}
function obf_flush() {
ob_end_flush();
ob_flush();
flush();
obf_start();
}
Is it an ugly solution? Yes it is. But until all the bugs related to output buffering are fixed, I don't see this work-around going away in production code any time soon.
Also note that some anti-virus software (Panda AV and others) and proxies will hold all data until the socket is closed. You cannot guaranty that all clients will receive proper flushed data.