From 9d10d53d9fc430fde2855f3fd58b84e193e499ad Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 26 Feb 2020 21:41:38 +0100 Subject: [PATCH] Fixes album export by reducing memory usage of the scripts. Chunks the output buffer to 4kB chunks. This means the Download.php script will no longer run out of memory when trying to stream a tar file the output buffer. --- app.php | 2 +- controllers/Download.php | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app.php b/app.php index 6ef0d72..03392a0 100644 --- a/app.php +++ b/app.php @@ -27,6 +27,6 @@ set_error_handler('ErrorHandler::handleError'); ini_set("display_errors", DEBUG ? "On" : "Off"); // The real magic starts here! -ob_start(); +ob_start(null, 32768); Dispatcher::dispatch(); ob_end_flush(); diff --git a/controllers/Download.php b/controllers/Download.php index b1bcb95..c466100 100644 --- a/controllers/Download.php +++ b/controllers/Download.php @@ -53,20 +53,6 @@ class Download extends HTMLController { $files = array(); - $album_ids = array_merge(array($album->id_tag), $this->getChildAlbumIds($album->id_tag)); - foreach($album_ids as $album_id) - { - $iterator = AssetIterator::getByOptions( - array( - 'id_tag' => $album_id - ) - ); - while($asset = $iterator->Next()) - { - $files[] = join(DIRECTORY_SEPARATOR, array('.', $asset->getSubdir(), $asset->getFilename())); - } - } - $descriptorspec = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), @@ -93,8 +79,19 @@ class Download extends HTMLController header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: binary'); - foreach($files as $file) - fwrite($pipes[0], $file . "\0"); + $album_ids = array_merge(array($album->id_tag), $this->getChildAlbumIds($album->id_tag)); + foreach($album_ids as $album_id) + { + $iterator = AssetIterator::getByOptions( + array( + 'id_tag' => $album_id + ) + ); + while($asset = $iterator->Next()) + { + fwrite($pipes[0], join(DIRECTORY_SEPARATOR, array('.', $asset->getSubdir(), $asset->getFilename())) . "\0"); + } + } fclose($pipes[0]); -- 2.46.0