One of my sites has 150,000 plus attachments in 5 directories. It runs OOM when trying to reach attachment settings or folders in the ACP. Could that be addressed here?
@badmonkey that sounds odd, I'm not sure why it should have such a problem. :-\
If it's unusual not sure how to troubleshoot it? Raising the php memory limit to 2G allows the interface to work. If it is indeed unusual, does anyone else using elk have attachment directories as large?
Not this large, Badmonkey. We have 66.790 attachments with 3.827.119 KB
I split the topic so the discussion is easier to follow.
On which page exactly goes out of memory? (Just to be sure.)
Thanks for addressing it eman. ;)
ACP > Attachment Directories
and
ACP > Attachment Settings > Manage Attachment Directories
both result in 500 errors due to OOM. I said 2G memory limit will cover it, and it will, but don't know the EXACT limit that will work. :-X
Is that 1.0 or 1.1 (I'm not sure its any different but just want to be sure)
Could possibly be this code
// Count the files with a glob, easier and less time consuming
$num_files = count(glob($dir . '/*.elk'));
EDIT: Tested with 180k files in one dir, down to 7MB memory from 40+MB. In ./sources/subs/ManageAttachments.subs.php, find the above code and replace with
// Count the files with an iterator for a smaller memory footprint.
$num_files = count(new GlobIterator($dir . '/*.elk'));
EDIT2: This is 1.0.
The forum in question uses 1.1. 8)
https://github.com/elkarte/Elkarte/blob/c58a9e6ecf9ea836d77d02a2ff458b7413b755bf/sources/subs/ManageAttachments.subs.php#L1282
$num_files = count(iterator_to_array($glob));
replace wth
$num_files = $glob->count();
It looks like you can't backport that fix to 1.0.x because it requires PHP 5.3 or higher. :)
Thanks for the debug :D ... I added this to the 1.1 tracker so we don't miss this in the final.
Thanks Spuds!
I wanted to do it this morning but I was already a bit late. O:-)