哪个在PHP中性能更好? [英] Which is better performance in PHP?

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

问题描述

我通常将1个函数文件包含在我网站的黑客中,现在这个网站流量非常高,我只想把每件小事做到最好,所以我的问题是,

I generally include 1 functions file into the hader of my site, now this site is pretty high traffic and I just like to make every little thing the best that I can, so my question here is,

是否更好地包含多个较小的函数类型文件,只包含该页面所需的代码,或者将它全部加载为1个大文件真的没什么区别,我当前的函数文件有我整个网站的所有功能,它大约有4,000行,并且在整个网页上加载,是不是很糟糕?

Is it better to include multiple smaller function type files with just the code that's needed for that page or does it really make no difference to just load it all as 1 big file, my current functions file has all the functions for my whole site, it's about 4,000 lines long and is loaded on every single page load sitewide, is that bad?

推荐答案

很难说。在文件解析领域,4,000行并不是那么大。在代码管理方面,这已经开始变得笨拙,但是你不太可能通过将其分解为2,5或10个文件来看到可测量的性能差异,并且页面只包含他们需要的少数几个(这是更好的编码实践,但这是一个单独的问题)。您的行数读取与解析器需要打开的文件数量之间的差异似乎不足以保证任何重要性。我最初的反应是,这可能不是你需要担心的问题。

It's difficult to say. 4,000 lines isn't that large in the realms of file parsing. In terms of code management, that's starting to get on the unwieldy side, but you're not likely to see much of a measurable performance difference by breaking it up into 2, 5 or 10 files, and having pages include only the few they need (it's better coding practice, but that's a separate issue). Your differential in number-of-lines read vs. number-of-files that the parser needs to open doesn't seem large enough to warrant anything significant. My initial reaction is that this is probably not an issue you need to worry about.

在硬币的另一面,我参与了一个企业级项目,其中一些操作有一个 include()树,它经常扩展到数百个文件中。对这些操作进行分析表明, include()调用所花费的时间仅占用了10秒加载操作的2-3秒(这是PHP4)。

On the opposite side of the coin, I worked on an enterprise-level project where some operations had an include() tree that often extended into the hundreds of files. Profiling these operations indicated that the time taken by the include() calls alone made up 2-3 seconds of a 10 second load operation (this was PHP4).

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

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