Search code examples
phpperformancedirectoryoverhead

How much does getting a list of directories affect php's performance


Very simple question this time, basically I have a group of folders and some of them contain files that I would like to autoload whenever I run my sites script. However I do not want to have to specify what files to autoload because I want the process to be dynamic and I want to be able to create and delete different files on the fly. So of course the easiest solution is to get a list of folders in the directories and build the paths to the auto load files, if the files exist then the script includes them. But, my question is how much will that affect the performance of my script? Its actually a framework which I want to release later on so performance is quite the issue. Any Ideas?


Solution

  • You should consider simply letting PHP autoload your classes.

    If that won't work, then you're pretty much left with the directory-scanning solution, and you shouldn't really care about performance penalties. If you want the functionality, you'll put up with the costs.

    Generally you shouldn't stress overmuch about performance in PHP anyways. If it becomes an issue when your framework is complete, revisit it. Chances are you'll find whatever performance gains/losses you incur now are rendered moot by implementing a good caching system in your framework.

    See Premature Optimization.