Am having a folder with millions of files in the server
File name will be LMN20110305.txt pattern.
If i am trying to search for files in april only am now reading directory
getting the filename and using substring am checking it is greater than or less than of
20110401 and 20110430
In this case it will read entire directory and it is taking so many hours.
Am thinking about checking create date also.
How will be the performance of glob — Find pathnames matching a pattern
Any one have any better suggestion?
Silly doubt! Is it possible to find the files without searching entire directory?
glob()will perform fine. It’s in the standard library for a reason, use it!It’s my understanding that
glob()maps almost directly to theglob()function in your system’s C library, meaning that it will most likely be more efficient than anything you roll your own. The only limit is memory: if you run out of memory, you’ll either need to give PHP more memory or reorganize.If you run in to memory problems, how about organizing your files a little better? A million files in one folder is way too many. Organize them somehow. If your files are dated, try organizing them by year (and then maybe month), along the lines of: