Reputation: 77
Is there anything wrong in the practice that consists of creating physical directories for each post (which is created) and each user (who registers) on a website?
For an architecture which resembles:
www.site.com/u/john
www.site.com/u/mike
www.site.com/post/za634df
www.site.com/post/df124zs
(PHP, Linux based FYI).
I indeed always thought I needed a physical folder if I wanted a post URL to be able to be shared on Facebook for example etc. Is this true?
Plus, by doing so, would I run into problems? slow downs? server directories limits? etc.
Upvotes: 1
Views: 25
Reputation: 3692
I don't think it's a terribly good idea. For one, it's orders of magnitudes slower to manipulate the filesystem than to make an entry in a database, so there's this obvious performance loss, and the number of subdirectories may be limited depending on the filesystem (which may cause portability issues on the long run). There may be other effects, but those would come up with only really big traffic.
But the design perspective is much more important here: the physical file structure is a wholly different layer than the URI layout, which is an abstraction for it. By tying your URI scheme to the physical layout you discard the advantages of this abstraction. As usual with design principles, this may not seem like a big deal if your project is small, short-lived, or you're in a big hurry and don't care; but on the long run, keeping the separation of concerns can be quite vital for everybody's sanity.
That said, your idea may have merits if properly implemented, though in my opinion it'd be better to use a database and an URL-rewriting engine (like Apache's mod_rewrite) to achieve the same effect. And even if you do end up creating folders for everything, make absolutely sure that the procedure is properly abstracted and no piece of code relies on stuff being in the same directory, and no piece of code actually manipulates the filesystem dirctly (relying instead on a single unified helper class to do it).
Oh and, no, Facebook can't see what's behind your URI scheme.
Upvotes: 1
Reputation:
Why Would you want to make several directories for each user and add same codes in each directory when you can simply handle them all using rewrite url
from a single script .
Several scripts will also cost you much-much more storage and will make you cry while updating or adding some new feature in your site.
Upvotes: 1