One 'compressed' file of classes vs multip

2019-08-05 02:31发布

问题:

Is there any gain to combining all of the classes for a project into one massive 'compressed' file (spaces and comments removed) vs loading each class as they are required (other than all of the classes are there so you don't have to require/include them, isn't that what we have __autoload for?)?

It seems to me that loading each class as needed would be a lot less strenuous on php.

回答1:

Generally, in the vast majority of cases, for any non-trivial number of classes, you want some kind of dependency injection. The overhead of the dependency injection (via whatever method) will be dwarfed by the resources needed to parse a bunch of classes that won't get used in a particular request.

A lot has been written on the subject of how to efficiently manage loading classes as needed.



回答2:

If you use a bytecode cache like APC, there's likely no performance gain to be had from "minifying" your PHP (removing whitespace and comments). The only benefit would be obfuscation -- which isn't going to buy you much anyway.

And yes -- loading 30 classes when you only need 1 is going to be a waste of resources.



标签: php class