views:

170

answers:

0

I'm sending files in action helper for downloads (in parts if needed) like this:

...
$response->sendHeaders();

$chunksize = 1 * (1024 * 1024);
$bytesSent = 0;

if ($httpRange) {
    fseek($file, $range);
}

while(!feof($file) &&
   (!connection_aborted() &&
   ($bytesSent < $newLength))
) {
    $buffer = fread($file, $chunksize);
//      $response->appendBody($buffer); // this would be better
    print($buffer);
    flush();
    $bytesSent += strlen($buffer);
}
fclose($file);

I suspect that better way would be to make use of $response object instead of print.

Which is the recommended way to send big response objects using Zend Framework?