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

…衆ロ難τιáo~ 提交于 2020-01-24 22:47:47

问题


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.



来源:https://stackoverflow.com/questions/1424382/one-compressed-file-of-classes-vs-multiple-class-files-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!