很抱歉,如果这是基本的,我正在尝试尽可能多地学习PHP中的OO,我正在慢慢学习如何使用它(非常有限)。
所以我想知道__autoload()是否对PHP操作码缓存有任何影响?
答案 0 :(得分:27)
操作码缓存在自动加载中起作用(或者至少应该起作用)但是你可能会受到性能影响。
来自Remember: be nice to byte code caches:
<arnaud_> does autoload have a performance impact when using apc ?
<Rasmus_> it is slow both with and without apc
<Rasmus_> but yes, moreso with apc because anything that is autoloaded is pushed down into the executor
<Rasmus_> so nothing can be cached
<Rasmus_> the script itself is cached of course, but no functions or classes
<Rasmus_> Well, there is no way around that
<Rasmus_> autoload is runtime dependent
<Rasmus_> we have no idea if any autoloaded class should be loaded until the script is executed
<Rasmus_> top-level clean deps would speed things up a lot
<Rasmus_> it's not just autoload
<Rasmus_> it is any sort of class or function declaration that depends on some runtime context
<Rasmus_> if(cond) function foo...
<Rasmus_> if(cond) include file
<Rasmus_> where file has functions and classes
<Rasmus_> or heaven forbid: function foo() { class bar { } }
当然有条件地澄清 包含的文件得到编译和 缓存。这个问题不包括在内 文件,但结果有条件 定义了需要的类和函数 在每个请求上重新定义。 这是否重要 归结为具体情况 情况,但毫无疑问 它比较慢。它归结为NOP 与FETCH_CLASS相比,例如和 NOP明显更快。
答案 1 :(得分:16)
(免责声明:我只知道APC)
操作码缓存的作用是:
重点是,这里是入口点:文件的完整路径。
自动加载通常做的是:
因此,与操作码缓存相关的信息(文件的完整路径以及包含/需要它的事实)仍在此处。
因此,自动加载不会给操作码缓存带来任何麻烦。
(并且,在使用APC时,据我所知,它没有)