-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Currently the performance of external storage is bad because the file must first be downloaded into a temporary file, then fopen() is called on that file and the handle is returned. This means that downloading a 4 GB file from an ext storage will first create a 4 GB temporary file which is then passed to the client as download.
In some cases like downloading, mimetype scanning (if we keep it), antivirus app, etc we are only interested in getting either the first bytes of the stream (fread() then fclose()) or stream the whole file sequentially. No fseek() needed.
In such cases, it might be more efficient to do a fopen() on the stream directly, if possible. It seems that PHP allows fopen() on HTTP URLs. We could just stream the body of the response as it comes into the hooks and back to the client.
I had a quick look and it looks like most external storages could be modified to use streaming, as many of them use HTTP calls anyway.
The alternative to this would be to use a library like CURL that uses threads to pre-download the file into the temporary file. The control could be given back to the caller before the file is finished downloading, so that they can already start working on the start of the temporary file.
Please let me know what you think of this idea.
@icewind1991 @karlitschek @schiesbn @DeepDiver1975 @bantu
List of storages
- SMB (possible since 8.2 with the SMB library from @icewind1991 and libphp5-smbclient)
- FTP (might be possible with stream wrapper)
- SFTP
- WebDAV
[WIP] Use stream wrapper that allows to seek HTTP files #11000stream webdav downloads using http client #18653 - ownCloud
- Federated shares
- S3
- SWIFT: Streaming download from Swift in files_external #19002
- Dropbox
- GDrive: Stream upload/download for GDrive #21357