The function scandir() heavy?

This: folder with 5000-6000 images, which are constantly changing
If you want to choose a random picture, whether to use this feature?
July 9th 19 at 13:34
1 answer
July 9th 19 at 13:36
Solution
use DirectoryIterator, it will be faster.

php.net/manual/ru/class.directoryiterator.php
better yet, make a file Manager. So they're all somewhere casinopolis, and not requested every time you access the file system. for example in memcached to throw an array of files, or updating files to update and memcached'e. And for a sample you will not need to re-scan the directory and just pull the array from the cache and to select a random item. It will be even faster. Either store in the database, and to do the same thing using f-II DBMS. - audrey_Kautz commented on July 9th 19 at 13:39
Just to complicate caching and the database is not wanted at this stage. That is, I understand that the list of files we are receiving brute force of all elements in the directory? That is, the operating system has no ready-made list of files in a folder - Martine.McDermot commented on July 9th 19 at 13:42
maybe he is, but it is still necessary to consistently iterate - audrey_Kautz commented on July 9th 19 at 13:45

Find more questions by tags PHP