Php – How to protect large file downloads through PHP and/or Apache

apache-2.2httpPHPweb-server

We have some large files (1-8GB) that are not publicly accessible. Currently we're serving them up through a PHP script that buffers the files in 1MB chunks and writes it to the output. It's incredibly CPU intensive and slows the server down when only a few downloads are active. We want to move the file transfer work to Apache or a more efficient method. We are using cookie authentication. FTP downloads are out unless there's some way to authenticate FTP sessions through the existing PHP session cookie.

Ideally we'd like something where we can use PHP to hide the link to the file while it passes off the file transfer work to Apache, which is no doubt far more efficient at HTTP file transfers than PHP. We want to be able to resume downloads as well.

Any help is appreciated.

Best Answer

X-Sendfile is made specifically for this type of operation. You can read about it at http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/