简体   繁体   中英

One 'compressed' file of classes vs multiple class files in PHP

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM