I'm running tests on different boxes but all behave the same way.
The files I'm using are way big (around a gig in size) and are not on the same LAN, so I've got plenty of time to do whatever test I need 🙂
I'm doing something different than using fpassthru() because I need to do some checks and write a row in a db every once in a while while sending the file. So my script looks more like:
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $l["nomefile"] . "; size=" . $l["dimensione"]);
header("Content-Length: " . $l["dimensione"]);
// Download can take a while... no max time limit
set_time_limit(0);
$fp = fopen($l["path"] . "/" . $l["nomefile"], "rb");
$bread=0;
$lastperc = 0;
$lastrun = time();
while (!feof($fp)) {
$buf = fread($fp, 1024);
$bread += 1024;
echo $buf;
$perc = floor(($bread/$l["dimensione"])*100);
if ( (($perc % 10) == 0) && ($perc != $lastperc)) {
$lastperc=$perc;
//echo "perc: $perc / $bread / " . $l["dimensione"] . "<br>";
$sql = "update sessioni_scrocco set percentuale = " . $perc . " where " .
"(hash = '" . $HTTP_GET_VARS["hash_coda"] . "') and " .
"(id_utente = '" . $HTTP_SESSION_VARS["multiplayer_userid"] . "')";
$q = mysql_db_query("tanis", $sql, $hu);
}
$thisrun = time();
//Aggiorna la riga ogni 2 secondi
if ( ($thisrun - $lastrun) > 2 ) {
$lastrun = $thisrun;
$sql = "update sessioni_scrocco set ultimogiro = '" . $lastrun . "' where " .
"(hash = '" . $HTTP_GET_VARS["hash_coda"] . "') and " .
"(id_utente = '" . $HTTP_SESSION_VARS["multiplayer_userid"] . "')";
$q = mysql_db_query("tanis", $sql, $hu);
}
}
fclose($fp);