1

Possible Duplicate:
Sending large files reliably in PHP

I will be distributing a PHP script which enables people to provide downloadable products to their clients from their server via a masked URL (don't want to give away the location on the server). Some files may be pretty large, so I need to make sure I use a method which is capable of handling larger files.

I am familiar with how to utilize each of the following download methods, I am just asking which would be the best to use (most efficient, reliable, universally supported, etc.):

Streaming fopen

Streaming cURL

file_get_contents

cURL

Community
  • 1
  • 1
MultiDev
  • 10,389
  • 24
  • 81
  • 148
  • I'm not sure why you need any of those functions to serve a download? Can you explain better? – drew010 Jun 27 '12 at 23:34
  • 2
    None of those you've listed. There is `readfile` and actually better is to delegate the job for serving back to the webserver, e.g. `X-Sendfile`. – hakre Jun 27 '12 at 23:34
  • Its a large script with a lot of functionality, without explaining everything about it, I just need to know the best way for the script to serve a large download. – MultiDev Jun 27 '12 at 23:35

1 Answers1

5

It's generally best to let the webserver handle sending static files.

Use x-sendfile for apache, lighttpd or nginx. You can use php for auth, send the X-Sendfile header, the script will terminate, and the web server will handle the sending of the file. The end user will never know where the file is on the server.

Cameron Martin
  • 5,952
  • 2
  • 40
  • 53