|
WorkingWithLargeFiles
dealing with large file up and downloads
Phase-Implementation Using streamsIn order to allow transfers of big files, SabreDAV makes use of streams everywhere internally. This allows you to deal with very large files (I've tried up to 2GB up/down, and others up to 15GB), without requiring a high number for memory_limit. Basically this means you should use fopen() whenever you open files through a get method: ...
function get() {
return fopen('file','r');
}
createFile() and put() also get open streams as arguments. You can safely use file_put_contents here, because if it encounters a stream as it's second argument it will work as stream_copy_to_stream. In order for this to be effective, you must make sure you're not using output buffering. Make sure the output_buffering setting is set to Off, and don't use ob_start() before any large file output. If you intend to do pre or post-processing within php, you should use temporary files and process it in for example 2M chunks (or lower/higher?). Better yet, use the php://temp stream. This special stream handler keeps the entire file into memory, but will switch to disk if the file exceeds 2MB. HTTP Digest caveatThe standard HTTP Digest class will advertise support for integrity checking. This means it will run an md5 on the entire request body and need the entire memory in file. Although most clients I've seen don't actually use this, there could be a few out there that do. By default this is turned off though. Apache mod_reqtimeoutIt was reported that Apache's mod_reqtimeout can stop large uploads from completing. This module is currently enabled by default on Ubuntu, and perhaps others as well. To fix this, turn off the module. | |