Welcome Guest, Not a member yet? Register   Sign In
Is glob a bad idea?
#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?


Messages In This Thread
Is glob a bad idea? - by El Forum - 11-17-2009, 10:32 AM
Is glob a bad idea? - by El Forum - 11-17-2009, 10:35 AM
Is glob a bad idea? - by El Forum - 11-17-2009, 10:38 AM
Is glob a bad idea? - by El Forum - 11-17-2009, 10:55 AM
Is glob a bad idea? - by El Forum - 11-17-2009, 11:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB