Commit fb28fd40 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-797 GetAttachment use fpassthru (more efficient).

Released under the Affero GNU General Public License (AGPL) version 3.
parent f0039677
...@@ -66,20 +66,13 @@ class GetAttachment extends RequestProcessor { ...@@ -66,20 +66,13 @@ class GetAttachment extends RequestProcessor {
throw new StatusException(sprintf("HandleGetAttachment(): No stream resource returned by backend for attachment: %s", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); throw new StatusException(sprintf("HandleGetAttachment(): No stream resource returned by backend for attachment: %s", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
$l = 0; self::$topCollector->AnnounceInformation("Starting attachment streaming", true);
while (!feof($stream)) { $l = fpassthru($stream);
$d = fgets($stream, 4096);
$l += strlen($d);
echo $d;
// announce an update every 100K
if (($l/1024) % 100 == 0)
self::$topCollector->AnnounceInformation(sprintf("Streaming attachment: %d KB sent", round($l/1024)));
}
fclose($stream); fclose($stream);
self::$topCollector->AnnounceInformation(sprintf("Streamed %d KB attachment", $l/1024), true); if ($l === false)
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment with %d KB sent to mobile", $l/1024)); throw new FatalException("HandleGetAttachment(): fpassthru === false !!!");
self::$topCollector->AnnounceInformation(sprintf("Streamed %d KB attachment", round($l/1024)), true);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment with %d KB sent to mobile", round($l/1024)));
} }
catch (StatusException $s) { catch (StatusException $s) {
// StatusException already logged so we just need to pass it upwards to send a HTTP error // StatusException already logged so we just need to pass it upwards to send a HTTP error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment