6.0.0-beta13
▾
Tasks
New Task
Search
Photos
Wiki
▾
Tickets
New Ticket
Search
dev.horde.org
Toggle Alerts Log
Help
4/11/26
H
istory
A
ttachments
C
omment
W
atch
Download
Comment on [#5913] Lower memory usage while downloading files
*
Your Email Address
*
Spam protection
Enter the letters below:
.__ .___. ,. .. . [ __[__ \./ |\/|| | [_./| | | ||/\|
Comment
> Gollem (probably Horde as an application entirely) needs quite a > memory footprint (PHP memory_limit) for downloading mail attachments > or downloading files from Gollem. > > > > I haven't tested this problem in the latest and greatest of Horde, > but all tickets and forums I've seen indicate this is no different in > teh current release. > > > > The problem comes from the fact that the entire file that is about to > be downloaded is read entirely into memory (on the server) before it > is pushed out to the browser. This basically means that a 200MB file > stored in Gollem needs a PHP memory_limit of at least 200MB to be > able to download it. If one foreach is used on the array storing the > file in memory, the memory_limit doubles. > > > > To get around this problem is easy, push out the file in chunks, > instead of all at once. I have no idea how Gollem (or Horde) pushes > out a file to a browser, but I'd imagen it would be similar as I do > below. > > I think the below code is easy enough to read without me blabbering > on about it... Its code I use myself for a similar sort of function. > And, as far as I'm concerned, is available for Horde to use. I've > basically created the code myself using code templates for ideas I > found on various places on the net. > > Using this code, PHP's memory_limit can be left at default 8MB, and > any sized file can be downloaded. > > > > Questions? Do ask! > > > > Function ReadFileChunked ($FileName) { > > $chunksize = (102400); // how many bytes per chunk > > $buffer = ''; > > $handle = fopen($FileName, 'rb'); > > if ($handle === false) { return false; } > > while (!feof($handle)) { > > $buffer = fread($handle, $chunksize); > > print $buffer; > > } > > return fclose($handle); > > } > > > > { $File["File"] = "200MBfiletobedownloaded.zip"; > > $File["Size"] = FileSize($File["File"]); > > Header("Content-Type: application/force-download;"); > > Header("Content-Disposition: attachment; > filename=\"".$File["File"]."\""); > > Header("Content-Length: ".$File["Size"]); > > ReadFileChunked($File["File"]); > > Exit; > > } > >
Attachment
Watch this ticket
N
ew Ticket
M
y Tickets
S
earch
Q
uery Builder
R
eports
Saved Queries
Open Bugs
Bugs waiting for Feedback
Open Bugs in Releases
Open Enhancements
Enhancements waiting for Feedback
Bugs with Patches
Enhancements with Patches
Release Showstoppers
Stalled Tickets
New Tickets
Horde 5 Showstoppers