Mesié
Mesié

Reputation: 23

PHP flush() / ob_flush() not working only with Android browser

I have found similar questions but none as specific as this one. The following code is a simplified version that reproduces the problem.

<?php 
function addProgressText($texto)
{
  echo '<script type="text/javascript">'; 
  echo 'document.getElementById("mensajesEnProgreso").innerHTML += "'.$texto.'";';  
  echo '</script>';
  flush();
  ob_flush();
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>TEST - Flush for Android</title>
</head>

<body>
  <div id="divEnProgreso">
    <p id="mensajesEnProgreso"></p>
  </div>

<?php
addProgressText("Init...");
sleep(5);
addProgressText("OK<br>Step 1... ");
sleep(5);
addProgressText("OK<br>Step 2... ");
sleep(5);
addProgressText("OK<br>Step 3... ");
sleep(5);
addProgressText("OK<br>FINISHED");
?>
</body>
</html>

The code works as expected (displays the steps one by one) on Chrome, Firefox and IE, but when I open it from an Android browser, the flushes don't work and everything is displayed at once upon completion.

Any hints on the source of the problem? Thanks

Upvotes: 2

Views: 465

Answers (1)

fab
fab

Reputation: 1859

The reason for that is surely the 4K buffering in the Android browser. The only option you have is to pad the output to 4K as described in this bug report.

Upvotes: 0

Related Questions