PHP 性能受到 require() 的影响 [英] PHP performance hampered by require()

查看:47
本文介绍了PHP 性能受到 require() 的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 xdebug 分析器运行我的代码,发现超过 30% 的时间花在 require() 调用上.改善这一点的最佳方法是什么?我看到了一些关于使用 __autoload 的帖子,但是关于它对 APC(我们使用的)的影响存在相互矛盾的陈述,并且怀疑它用于提高性能.

I ran my code through xdebug profiler and saw more than 30 percent of the time is spent on the require() calls. What is the best way to improve on this? I saw some posts about using __autoload, but there were conflicting statements about it's affect on APC (which we use), and doubts about it's use to improve performance.

推荐答案

需要消耗时间的原因是磁盘 IO 速度.您可以尝试使用自动加载,因为您可能需要实际未使用的文件.另一种减少磁盘 IO 开销的方法是将您的 PHP 文件合并为一个大文件.需要一个包含您始终需要的代码的大文件比将相同的代码包含在多个小文件中要快.

The reason why requires consume time is disk IO speed. You can try using autoloading, as you may be requiring files that aren't actually used. Another approach to reduce the disk IO overhead is to combine your PHP files into one large file. Requiring a big file which contains the code you always need is faster than including the same code in multiple small files.

此外,APC 有一个功能可以加速需要,称为 apc.include_once_override,您可以尝试启用它.

Also, APC has a feature which speeds up requires called apc.include_once_override which you can try enabling.

这篇关于PHP 性能受到 require() 的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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