0

I am creating a simple file manager for a CMS. I included a function that calculates the total size of a folder, but I noticed that it increases load times considerably.

The first thing that came up was an option to enable or disable performing those calculations and only display the size of individual files. But now I am thinking about the impact it would have on the server when, at some point and hypothetically speaking, the option is activated and in the directory there is a folder whose size is 1 TB or more (assuming that the file system allows it).

What do you think would happen to the server if it received a request to perform those big calculations? Would it be better to remove the option?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • How are you doing this calculation – RiggsFolly Jan 17 '21 at 00:38
  • Calculating on the fly every time like this will almost certainly never be a viable option. At the least, you could cache the value somewhere, and then you only have to recalculate when a file is added or removed. – Alex Howansky Jan 17 '21 at 00:39
  • You may try the codes in this link : [How to get directory size in PHP] (https://stackoverflow.com/questions/478121/how-to-get-directory-size-in-php). If you can use something like `passthru('du -h -s ' . $DIRECTORY_PATH)` then I believe the loading will not be great in a linux environement, but provided that your system allows it in your case. – Ken Lee Jan 17 '21 at 00:41

1 Answers1

0

PHP Can overload the system if you done it on PHP alone. You can use PHP native support for your Operating System to handle the calculations, because as far as I know, your OS cache the indexing result so calculating the folder size is not a problem.

reference: how-to-get-directory-size-in-php

Jericho Aquino
  • 176
  • 1
  • 7