I assume that reading the database will be faster than reading the file system.
You will be better off running a sql query and getting a count for each folder grouped.
SELECT COUNT(file), folderId As Count FROM photos WHERE folderId IN ('1', '2') GROUP BY folder
SELECT foldername, folderId FROM folders WHERE countFlag = 0;
if($Count > 5000):
$countFlag = 1;
else:
endif;
Note: If you need real code samples, I can hack something quickly. The above examples do not contain actual working code and are intended for theoretical purposes only. You will need to iterate over the returned rows as they are grouped by folder.
source
share