PHP操作码缓存与自动加载一起工作吗?
抱歉,如果这是基本的,我正在尽可能多地学习PHP中的OO,我正在慢慢地学习如何使用它(非常有限) 所以我想知道uu autoload()是否对PHP操作码缓存有任何影响?(免责声明:我只知道APC) 操作码缓存的作用是:PHP操作码缓存与自动加载一起工作吗?,php,autoload,opcode-cache,Php,Autoload,Opcode Cache,抱歉,如果这是基本的,我正在尽可能多地学习PHP中的OO,我正在慢慢地学习如何使用它(非常有限) 所以我想知道uu autoload()是否对PHP操作码缓存有任何影响?(免责声明:我只知道APC) 操作码缓存的作用是: 当包含/需要某个文件时,它将采用该文件的完整路径 检查与该文件对应的操作码是否已在RAM中(在操作码缓存中) 如果是,则返回这些操作码以便执行 如果没有,则加载文件并将其编译为操作码;并将操作码存储在缓存中 这里重要的一点是入口点:文件的完整路径 自动加载通常要做的是
- 当包含/需要某个文件时,它将采用该文件的完整路径
- 检查与该文件对应的操作码是否已在RAM中(在操作码缓存中)
- 如果是,则返回这些操作码以便执行
- 如果没有,则加载文件并将其编译为操作码;并将操作码存储在缓存中
自动加载通常要做的是:
- 获取类的名称
- 将其转换为文件名
- 包括/要求该文件
:
当然是有条件地澄清
包含的文件将被编译并保存
缓存。这个问题不包括在内
但结果是有条件的
定义的类和函数
在每次请求时重新定义。
无论这是否重要
归根结底,这就是问题的具体细节
但毫无疑问
它比较慢。归根结底是否定的
与FETCH_类相比,例如
NOP显然要快得多
这也是我的经验-操作码缓存不受AutoloadCache使用的影响。我不知道为什么它没有被提升。我刚刚开始了一篇关于这个问题的新文章,因为我想知道是否有spl_autoload_register->
<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 { } }