在PHP中包含太多文件会降低性能吗? [英] Does including too many files in PHP reduce performance?

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

问题描述


可能重复:

包含函数文件的效率(在PHP中)

在php中使用太多include()

如果是这样,最多要包含的文件数量是多少?

If so, what would be the recommended amount of files to include at most?

推荐答案

包含文件将做以下事情:

Including a file will do the following things:


  • 从磁盘读取文件。

  • 运行文件中的代码。

这两项操作都需要时间。没有多少时间,但即便如此,如果你有很多包含,它可以加起来,所以你的问题的基本答案是'是的,它可以影响表现'。

Both of these operations take time. Not much time, but even so it can add up if you have a lot of includes, so the basic answer to your question is 'yes, it can affect performance'.

然而,这种性能影响的规模非常小,远远超过编写质量良好的结构良好的代码(包括在单独的文件中保存单独的类/功能)的优势。

However, the size of that performance hit is pretty tiny, and is far outweighed by the advantages of writing good quality well structured code (which includes keeping separate classes/functionality in separate files).

说实话,如果您担心这些事情的表现,请尝试通过 xDebug <一>。这将显示您的代码的哪些部分占用了大量时间。 include()语句将显示在那里,但不太可能位于列表顶部附近。

Truth be told, if you're worried about the performance of these sorts of things, try running your code through a profiler such as xDebug. This will show you exactly what parts of your code are taking the most amount of time. include() statements will show up in there, but are very unlikely to be anywhere near the top of the list.

除非您正在编写一个包含Facebook等访客号码的网站,否则您不必担心 include()的性能。但是看一下xDebug的profiler输出,因为你的代码中可能还有其他东西比你预期的要慢得多,或者经常被调用,或循环太多次等等,并修复这些会对代码的性能产生重大影响。

Unless you're writing a site with visitor numbers like Facebook, then you're unlikely to need to worry about the performance of include(). But take a look at the profiler output from xDebug, because there are likely to be other things in your code that are going much slower than you expected, or are being called to often, or are looping too many times, etc, and fixing these will have a big impact on the performance of your code.

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

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