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.
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.
Is this change still useful? It seems like an array with only paths ($files) and not the file contents should not get so large as to hit a memory limit.
Is this change still useful? It seems like an array with only paths (`$files`) and not the file contents should not get so large as to hit a memory limit.
In the old situation the export would fail on the first chunk leaving behind a .tar of ~0kb, This means that the list of files of an album of around 270 pictures already consumed a considerable amount of memory. So I would still like to keep this more "streaming" approach as a optimization.
In the old situation the export would fail on the first chunk leaving behind a .tar of ~0kb, This means that the list of files of an album of around 270 pictures already consumed a considerable amount of memory. So I would still like to keep this more "streaming" approach as a optimization.
I don't think that's possible, because if the memory limit was hit while building the array of file names, there would be no tar file at all, since tar is invoked after $files has been built.
While I don't think the streaming approach is wrong, this feels like a premature optimization (and certainly one that should not be necessary).
I don't think that's possible, because if the memory limit was hit while building the array of file names, there would be no tar file at all, since `tar` is invoked after `$files` has been built.
While I don't think the streaming approach is wrong, this feels like a premature optimization (and certainly one that should not be necessary).
The current code uses proc_open, but you might want to look into passthru.
The current code uses [`proc_open`](https://www.php.net/manual/en/function.proc-open.php), but you might want to look into [`passthru`](https://www.php.net/manual/en/function.passthru.php).
I'm currently using ther tar's -T functionality to read a list of files in a file seperated by a "\0" byte. and I skipping the file all together by using - as the argument to -T and feeding it the files on STDIN. After a quick look at the passthru i don't think such a thing is possible. and I think i will run out of "command line" space to execute the tar command with passthru.
I'm currently using ther tar's -T functionality to read a list of files in a file seperated by a "\0" byte. and I skipping the file all together by using - as the argument to -T and feeding it the files on STDIN. After a quick look at the passthru i don't think such a thing is possible. and I think i will run out of "command line" space to execute the tar command with passthru.
Agreed that passthru is probably the better solution, especially if you're not expecting to handle anything on STDOUT or STDERR.
I do not think the proposed solution to use STDIN to manually feed filenames will provide much in the way of performance benefit. If anything, I think tar can enumerate files more quickly than a PHP script.
Agreed that `passthru` is probably the better solution, especially if you're not expecting to handle anything on `STDOUT` or `STDERR`.
I do not think the proposed solution to use `STDIN` to manually feed filenames will provide much in the way of performance benefit. If anything, I think `tar` can enumerate files more quickly than a PHP script.
I haven't looked at the rest of the framework, but you might want to consider disabling the output buffer before calling tar. This code could then check whether an output buffer is still active with ob_get_level.
I haven't looked at the rest of the framework, but you might want to consider disabling the output buffer before calling `tar`. This code could then check whether an output buffer is still active with [`ob_get_level`](https://www.php.net/manual/en/function.ob-get-level.php).
I agree with @minnozz; much better to disable it locally (i.e. in the download controller) with ob_end_flush. In general, output buffering is quite useful.
I agree with @minnozz; much better to disable it locally (i.e. in the download controller) with `ob_end_flush`. In general, output buffering is quite useful.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.
@@ -63,4 +56,0 @@);while($asset = $iterator->Next()){$files[] = join(DIRECTORY_SEPARATOR, array('.', $asset->getSubdir(), $asset->getFilename()));Is this change still useful? It seems like an array with only paths (
$files) and not the file contents should not get so large as to hit a memory limit.In the old situation the export would fail on the first chunk leaving behind a .tar of ~0kb, This means that the list of files of an album of around 270 pictures already consumed a considerable amount of memory. So I would still like to keep this more "streaming" approach as a optimization.
I don't think that's possible, because if the memory limit was hit while building the array of file names, there would be no tar file at all, since
taris invoked after$fileshas been built.While I don't think the streaming approach is wrong, this feels like a premature optimization (and certainly one that should not be necessary).
@@ -67,4 +56,1 @@}}$descriptorspec = array(The current code uses
proc_open, but you might want to look intopassthru.I'm currently using ther tar's -T functionality to read a list of files in a file seperated by a "\0" byte. and I skipping the file all together by using - as the argument to -T and feeding it the files on STDIN. After a quick look at the passthru i don't think such a thing is possible. and I think i will run out of "command line" space to execute the tar command with passthru.
Agreed that
passthruis probably the better solution, especially if you're not expecting to handle anything onSTDOUTorSTDERR.I do not think the proposed solution to use
STDINto manually feed filenames will provide much in the way of performance benefit. If anything, I thinktarcan enumerate files more quickly than a PHP script.@@ -28,3 +28,3 @@// The real magic starts here!ob_start();ob_start(null, 32768);I haven't looked at the rest of the framework, but you might want to consider disabling the output buffer before calling
tar. This code could then check whether an output buffer is still active withob_get_level.@aaron what are your thoughts on this? I'm not familiar enough to comment on this.
I agree with @minnozz; much better to disable it locally (i.e. in the download controller) with
ob_end_flush. In general, output buffering is quite useful.@@ -98,0 +83,4 @@foreach($album_ids as $album_id){$iterator = AssetIterator::getByOptions(array(This is an aside, but I'd like to stick to new-style (bracketed) arrays, that is
[]instead ofarray().This is being superseded by PR !19
Pull request closed