开发者

What are the downsides of using long directory paths/names and URL's on a LAMP site? [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

What are the downsides of longer directory paths/names and URL's on a LAMP site?

What are the downsides of longer directory paths/names and URL's on a LAMP site?

I am trying to organize images on my sites as efficiently as possible, and I'm keen on using many nested directories so that no sub-directory has more than 1,000 sub-directories and so that the directories are easy 开发者_如何学运维to maintain across many users.

In a worst-case scenario, images would be stored looking something like this:

./images/76/543/7654321/640/1.jpg

Are there any serious downsides to having so many sub-directories vs. something simpler like this:

./i/a7/c3/5e.jpg

I suppose the more sub-directories the Server has to dig in to, the longer it's going to take, and the longer the directory structure is, the longer the URL will be, so the more space the HREF will take up in the HTML doc. But how much of a difference will that make? Let's say we scale up to millions of users, is this something I need to take into consideration (short dir structure vs long dir structrue) or is it fine to go with the longer directory structure?

Thanks!


You could use a storage that "grows" with your needs and experience.

Let's assume you create the filename of the image based on the image itself, for example by using SHA1 on its content, e.g. b494ad9057e09277fd02e811bb8e86b322a5166b.jpg could be the name.

The image then is stored on the file system inside "images" directory.

The URI you use to access the file always is images/b494ad9057e09277fd02e811bb8e86b322a5166b.jpg.

Now, the magic happens inside mod_rewrite of your Apache. The requested resource could be split in any way you want, for example into images/b494ad9057e09277fd02/e811bb8e86b322a5166b.jpg (note the slash after the 20th character of the hash) and then loaded from there.

Once you got an answer from a file system expert, you can change the way the URI is split and move all files to their new expected location, as it always is possible to build the "original" filename by traversing the directory hierarchy.

Furthermore, a good hash should create "equally distributed characters" in the hash, so your directories should fill up in a balanced way, more or less.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜