"include"的性能成本是多少?在PHP中? [英] What's the performance cost of "include" in PHP?

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

问题描述

只是想知道是否有人知道与哪些成本"相关联,包括包含100多个类文件的大型(600K或更多)php文件.与自动加载单个文件(例如在找到匹配项之前跨多个目录进行搜索)相比,它真的有很大不同吗?

Just wondering if anyone has information on what "costs" are associated with including a LARGE (600K or more) php file containing 100s of class files. Does it really make much difference in comparison to autoloading individual files that for instance searches across several directories before finding a match?

是否可以使用APC缓存使费用微不足道?

Would having APC caching on make this cost negligible?

推荐答案

基本上,包含一个大文件的成本取决于您的用例.假设您有一个包含200个类的大文件.

Basically, the cost of including one big file depend on your usecase. Let's say you have a large file with 200 classes.

如果仅使用1个类,则对于该单个类,包括大文件将比包括小类文件贵.

If you only use 1 class, including the large file will be more expensive than including a small class file for that individual class.

如果全部使用200个类,则包括大文件将比包括200个小文件便宜得多.

If you use all 200 classes, including the large file will be significantly less expensive than including 200 small files.

临界点真正取决于系统.我会想像它会在50%左右(如果您在任何一个请求中使用的类少于100个,则会自动加载).

Where the cutoff lies is really system dependent. I would imaging that it would be somewhere around the 50% mark (where if you're using less than 100 classes in any one request, autoload).

使用APC可能会使收支平衡点更接近较少的类(因此,如果没有,则使用100个类可能是损益平衡点,但如果使用50个类,则可能会达到收支平衡点),因为它使大型单个产品的价格便宜得多,但是只会降低每个较小的包含的开销.

And using APC will likely shift the breakeven point closer to less classes (so without, 100 classes used might be the breakeven point, but with it might be at 50 classes used) since it makes the large single include much cheaper, but only lowers the overhead of each individual smaller include slightly.

确切的盈亏平衡点将取决于100%系统(磁盘I/O多快,处理器多快,多少内存等).因此,确定在您的平台上确定的唯一方法是进行测试.

The exact break-even points will be 100% system dependent (how fast is your disk I/O, how fast are your processors, how much memory, etc). So the only way to know for sure on your platform is to test.

但是,与原始性能相比,风险更大.一个大文件的可维护性会受到影响,因为同时处理多个类比较困难(IDE中的选项卡变得无用).我个人将所有类保存在单独的文件中,并使我作为开发人员的生活更加轻松,而不是使文件变得庞然大物.

However, more is at stake than raw performance. Maintainability will suffer with one large file since it's harder to work on multiple classes at the same time (tabs in an IDE become useless). I personally would keep all the classes in separate files and make my life as the developer easier rather than making one giant monstrosity of a file.

现在,如果您拥有Facebook流量水平,则可能值得进一步调查.但是,如果您不是,我个人不会担心...

Now, if you have facebook traffic levels, it may be worth investigating further. But if you're not, I personally wouldn't worry about it...

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

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