包含多个文件的PHP性能 [英] PHP Performance on including multiple files

查看:100
本文介绍了包含多个文件的PHP性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的工作流程包括功能和类文件以及何时需要。然而,这可能会变得非常混乱,你有很多,其中一些依赖于其他人。

My current workflow I include function and class files as and when I need to. However, this can get quite messy with you have quite a lot of them in which some depend on others.

所以我正在考虑使用包含在includes目录中的文件的头文件。但我的问题是,是否有任何PHP性能问题,包括我需要的时间。通常我必须使用 include_once ,所以做一个大包含就可以摆脱对此的需求。

So I'm considering using a head file which includes on the files in the includes directory. But my question is, are there any PHP performance issues for doing this over including as an when i need. Often times I have to use include_once, so doing 1 big include would get rid of the need for this.

推荐答案

最好的方法可能是自动加载。您根本不需要(手动)包含任何类。请查看。我建议使用 spl_autoload_register() -function 。这将动态解决依赖关系。在大多数情况下,包含的性能实际上是无关紧要的。缓慢的事情通常发生在其他地方。使用自动加载具有延迟加载的额外好处。您不加载未使用的源文件。这甚至可以加快您的申请。

The best approach would probably be autoloading. You do not need to (manually) include any class at all, then. Take a look at this. I recommend using the spl_autoload_register()-function. That would resolve dependencies on the fly. The performance of includes is really irrelevant in most cases. The slow things usually happen in other places. Using autoloading has the added benefit of lazy loading. You do not load source files that are not in use. This might even speed up your application.

这篇关于包含多个文件的PHP性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆