0

I am writing a script that needs to scan through a large amount of files (potentially up to 1 million) in a single directory (ext4). I am planning on using the PHP readdir function to create the list.

Since I don't have that amount of files in the directory yet, I don't know if it will work. I know 'ls' and such don't work on that amount of files, but I don't need them to.

So, the question is really only ...will PHP readdir work on 1 million files?

1
  • Can you just write a script that creates that number of files and test it?
    – WojtekT
    May 26, 2012 at 19:13

2 Answers 2

3

Why would you have so many files? It will kill your performance. Can't you group the data somehow? Or store it in a database? I can't really see how one million files in a sigle directory would make sense. The fragmentation would be enormous. Please give an example of the file you are storing.

3
  • They are images and the IDs of every single image will be stored in a mySQL database, which is there the application will later find every image to output, so that's not a problem. May 26, 2012 at 19:14
  • 1
    Store the images inside the database, that's your solution.
    – AlfredoVR
    May 26, 2012 at 19:16
  • or hash the files and group by the first letter of the hash like mediawiki does
    – Cole Tobin
    May 26, 2012 at 20:18
0

My answer to my own question, if anyone is wondering, is IT WORKS. I created a script to create 1 million random files and successfully ran the readdir function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.