关于APC的性能优化,请看下面这段话
If you want to make the best use out of autoload with an APC cache don’t use spl_autoload. It uses relative paths and thus will perform a stat even with apc.stat=0 (either that, or it doesn’t work at all).
Instead make a custom function and use require/include with an absolute path (register it with spl_autoload_register).
Do NOT use *_once functions or a relative path. This will fail harder than spl_autoload.
Also avoid using file_exists and is_file. This will also perform a stat.
Why are stats bad? Because they access the file system. PHP does have a stat cache that helps, but it defeats the purpose of apc.stat = 0.
It’s also good to keep in mind that it’s good to keep your custom autoload function simple. This is my Loader class:
class Loader { public static function registerAutoload() { return spl_autoload_register(array(__CLASS__, 'includeClass')); } public static function unregisterAutoload() { return spl_autoload_unregister(array(__CLASS__, 'includeClass')); } public static function includeClass($class) { require(PATH . '/' . strtr($class, '_\\', '//') . '.php'); } }
Also want to point out that APC does an optimization with require/include (not *_once) with relative paths if require/include is done in the global scope (and isn’t conditional). So it would be a good idea to explicitly include files you know you’re going to use on every request (but don’t use *_once). You could, for example, add a “registerProfiledAutoload” to the above class and keep track of what you’re including to help you determine what you could explicitly include (during development, not production). The key is try not to make heavy use out of autoload.
If you must use relative paths and don’t care about having to lower-case your file-names then spl_autoload works great.
建议继续学习:
- 使用APC来保护PHP代码 (阅读:4435)
- 关于PHP加速器APC的使用 (阅读:1908)
- 小心,apc可能导致php-fpm罢工! (阅读:1706)
- PHP5.2.x + APC的一个bug的定位 (阅读:1610)
扫一扫订阅我的微信号:IT技术博客大学习
- 作者:shen2 来源: 沈二铺子
- 标签: APC
- 发布时间:2012-03-26 22:02:49
- [53] IOS安全–浅谈关于IOS加固的几种方法
- [52] 如何拿下简短的域名
- [51] android 开发入门
- [51] 图书馆的世界纪录
- [50] Oracle MTS模式下 进程地址与会话信
- [49] Go Reflect 性能
- [46] 【社会化设计】自我(self)部分――欢迎区
- [46] 读书笔记-壹百度:百度十年千倍的29条法则
- [36] 程序员技术练级攻略
- [29] 视觉调整-设计师 vs. 逻辑