I am building a PHP CMS from the ground up. There is one super-core file within my system which I currently have automatically importing all other packages and classes that make up the core of the system. On a typical page, only a few of these classes and methods are used.
Considering the load require_once() puts on a server to include all of these files, and the time a user must wait for the page to load, I am wondering which path I should take:
- Keep the super-core as-is and automatically include all of the system core for each page that includes this core file.
- Use the super-core to include only essential packages, such as database management, and import additional packages/classes on an as-needed basis.
Could someone please let me know which of the two options are the best, as well as a brief overview of its pros and cons?
Thank you for your time!!!
Earlier this year, I came upon this exact problem while developing a framework in PHP.
I considered the pros-cons and here’s my evaluation:
Option 1 – Front Controller Pattern script include all other scripts
Advantages
Disadvantages
We have two classes
RectangleandShape.Rectangleis a child class i.e. extension ofShape. However the core script includes the classes alphabetically. Thus whenRectangleis included,Shapeis not found and PHP will throw an error.Rectangleclass:Shapeclass:Option 2 – Load main packages, then load other packages as-needed
Advantages
Disadvantages
Programming code is for human. Therefore to make things more logical and breaking down the problem, I chose option 2 to go for the framework.