0

Sorry if there is something wrong with this question. I'm developing website. But there is a confusing situation in my head about file system. Choosing to load files from few nested directory or deep nested directories? example:

A. file_get_contents('layout/guest/pages/home/data/slogan.txt');
   include_once 'layout/guest/required/front.php';

OR

B. file_get_contents('layout/slogan.txt');
   include_once 'layout/front.php';

Which performs faster?

I worry about this because there are lots of file system operations inside the website. If we look at the FileZilla operation, there seen that load many nested directories consuming more time. But I do not know, I hope your help. Thank you for all your helps :)

Jahe JS
  • 91
  • 1
  • 9

3 Answers3

2

Assuming you're using a UNIX-based OS there will be very little difference so you should use what you find easier to maintain. FTP is an entirely different case as it actually transverses directories as a human would (it doesn't have access to your inodes).

Because of how inodes work, your operating system is not going to transverse your directories one by one looking for a reference to another file. Directories exist to make your life easier but most filesystems do not represent them internally as anything more than an organizational file.

You will gain filesystem performance boost by enabling dir_index (instructions) on your extX filesystem (or alternatively, check out XFS as it's really good when dealing with large numbers of files), regularly cleaning out files and defragmenting the disk and using faster drives.

Also, try to use require_once() rather than require() when loading files, as this way the file will only be loaded a single time.

Glitch Desire
  • 14,632
  • 7
  • 43
  • 55
1

How deeply nested your directories are makes virtually no difference whatsoever. Only the number, size and complexity of the files you include matters, not what particular path they're included from.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

I think you're worrying about the wrong problem.

Depending on the operating system you're using, there's probably a slight overhead for using many directories rather than one - the OS needs to check permissions etc. However, on modern hardware, you'd be hard pushed to measure the impact, and caching at the OS level almost certainly wipes out any noticable impact.

The structure you show in your question shows a considered approach to putting files in a logical place - almost certainly, that's going to be better than bunching them all in the same directory from a maintainability point of view.

On the other hand, there's definitely some performance impact with include() and its friends.

Community
  • 1
  • 1
Neville Kuyt
  • 29,247
  • 1
  • 37
  • 52