Ticket #610 (closed Patch: fixed)

Opened 2 months ago

Last modified 3 weeks ago

Modification to Download helper for downloading large files

Reported by: SuicidalWeasel Assigned to: Shadowhand
Priority: minor Milestone: 2.2
Component: Helpers Version: SVN HEAD
Keywords: Download helper, download force, large files Cc:
SVN Revision (if applicable):

Description

The download helper is a great way to download files located outside the website root, but the size of files you can download with it is currently limited by the memory_limit defined in php.ini. This is because the entire file is read into memory before outputting to the browser. I've made some changes which loop through the file in smaller chunks and clear the output buffer each loop so the script doesn't run out of memory. I added a parameter of blocksize which specifies the amount of the file to be read at a time, defined in megabytes. The default is 1MB, which should be small enough for most servers with a memory_limit of 8MB or more. However, a developer can pass in a blocksize value if a particular server needs a smaller size or the developer knows his server can handle larger pieces.

Attachments

download.php (2.7 kB) - added by SuicidalWeasel on 05/15/08 18:02:34.
Modified download helper to handle larger file sizes

Change History

05/15/08 18:02:34 changed by SuicidalWeasel

  • attachment download.php added.

Modified download helper to handle larger file sizes

05/15/08 23:24:07 changed by Shadowhand

  • status changed from new to assigned.
  • owner changed from - No owner - to Shadowhand.

Thanks SuicidalWeasel?!

05/16/08 00:11:22 changed by SuicidalWeasel

No problem. I forgot to mention that I spent a good deal of time attempting to catch when the block size was too large and caused the file read to fail, without much success. When reading a block which is too large for memory, php reads the string, but then can't do anything with it. It simply returns an empty file. I tried checking for empty(), isset(), if (fread($file) === FALSE) and others but to no avail. I think because the string appears to be set even though it can't be used.

I eventually gave up and figured if a developer uses the helper and ends up with an empty file, they'll know they need to reduce the block size. However, if you could find a way to catch the failure, that'd be awesome.

Hope all that makes sense.

07/06/08 20:35:50 changed by Shadowhand

Can't this simply be solved by making sure the output buffer is closed before running fpassthru?

07/07/08 11:54:52 changed by champs

I haven't experienced quite the same problem, but from my experience, large block sizes are very much enjoyed over broadband, but they can choke even middleband connections. See my experiments with fread/blocksize and fpassthru.

07/07/08 14:00:14 changed by Shadowhand

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in r2982. Depends on r2981.