Welcome Guest, Not a member yet? Register   Sign In
Is glob a bad idea?
#1

[eluser]Ricardo SDL[/eluser]
Hi! I'm developing a little website where the users can upload images. I'm just putting all images in the same folder on the server and using the glob (http://php.net/manual/en/function.glob.php) function to get their addresses. With many images in the same folder, maybe thousands, the use of glob will show a great speed penalty?
#2

[eluser]Cro_Crx[/eluser]
yes.
#3

[eluser]Cro_Crx[/eluser]
More seriously, I would create the website now and only start optimising when you hit any speed issues. Having said that, attempting good design practises from the start will make everything a lot easier. Is it not possible to store the location of the images in the database for quick retrieval ? It would probably be a nicer way to implement it and wouldn't require much more code.

Best thing to do would be to try and see how you go. If the load times are slow then change it Smile

Also: I couldn't find any performance benchmarks for php's glob.
#4

[eluser]jedd[/eluser]
[quote author="Ricardo SDL" date="1258497140"]Hi! I'm developing a little website where the users can upload images. I'm just putting all images in the same folder on the server and using the glob (http://php.net/manual/en/function.glob.php) function to get their addresses. With many images in the same folder, maybe thousands, the use of glob will show a great speed penalty?[/quote]

Any directory scan is expensive, especially across that many entries. Different file systems will have different performance metrics under different conditions - the fact that you're asking, without a) mentioning what file system you're using, and b) sharing the results of your load testing so far - suggests that you probably haven't put much thought into this, or cut much code, yet.

Why aren't you renaming the files to something guaranteed unique (and safe) on the way in, and indexing the original names in a database (or even a flat file if you're feeling energetic / lazy). md5 / sha1 are the obvious candidates - you get consistent length filenames that are safe on every file system, and you can easily shuffle them into subdirectories based on, for example, the first two characters.

None of this is at all related to CodeIgniter, is it?
#5

[eluser]Ricardo SDL[/eluser]
Thank you for the tips! I changed the implementation to not rely on the glob function anymore. I'm using the database to store the file name, the lookups using a relational database are pretty fast.




Theme © iAndrew 2016 - Forum software by © MyBB