PHP 操作码缓存可以与 __autoload 一起使用吗?

发布于 2024-08-04 18:24:41 字数 109 浏览 4 评论 0原文

抱歉,如果这是基础知识,我正在尝试尽可能多地学习 PHP 中的 OO,并且我正在慢慢学习如何使用它(非常有限)。

所以我想知道 __autoload() 是否对 PHP 操作码缓存有影响?

Sorry if this is basic, I am trying to learn as much as I can about OO in PHP and I am slowly learning how to use it (very limited).

So I am wanting to know if __autoload() has any affect on PHP opcode cache's?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-08-11 18:24:41

操作码缓存可以(或至少应该)与自动加载一起工作,但您可能会受到性能影响。

来自记住:善待字节码缓存

<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 { } }

这封来自 Ramus 的邮件

澄清,当然是有条件的
包含的文件被编译并
缓存。问题不包括在内
文件,但结果有条件
定义的类和函数需要
根据每个请求重新定义。
无论这是否重要
归结为具体的
的情况,但毫无疑问
它比较慢。归结为NOP
与 FETCH_CLASS 相比,例如
NOP 显然要快得多。

Opcode caches work (or at least should work) with autoloading but you can potentially take a performance hit from.

From 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 { } }

and this mail from Ramus:

To clarify, of course conditionally
included files get compiled and
cached. The issue is not the included
files but the resulting conditionally
defined classes and functions needing
to be redefined on every request.
Whether that is significant or not
comes down to the specifics of the
situation, but there is no doubt that
it is slower. It comes down to a NOP
vs. a FETCH_CLASS, for example and the
NOP is obviously way faster.

嘿嘿嘿 2024-08-11 18:24:41

(免责声明:我只知道 APC)

操作码缓存的作用是:

  • 当包含/需要文件时,它会获取该文件的完整路径,
  • 检查与该文件对应的操作码是否已在 RAM 中(在操作码缓存中)
    • 如果是,则返回这些操作码以便执行它们
    • 如果没有,加载文件并将其编译为操作码;并将操作码存储在缓存中。

这里重要的一点是入口点:文件的完整路径。

自动加载通常做的是:

  • 获取类的名称
  • 将其转换为文件的名称
  • 包含/需要该文件

因此,与操作码缓存相关的信息(文件的完整路径以及它被包含的事实) /必需)仍然在这里。

因此,自动加载不会给操作码缓存带来任何麻烦。

(而且,据我所知,当使用 APC 时,情况并非如此)

(Disclaimer : I only know APC)

What an opcode cache do is :

  • when a file is included/required, it take the full path to that file
  • check if the opcodes corresponding to that file are already in RAM (in opcode cache)
    • if yes, return those opcode so they are executed
    • if no, load the file and compile it to opcodes ; and store opcodes in cache.

The important point, here, is the entry point : the full path to the file.

What autoloading generally do is :

  • get the name of a class
  • transform it to the name of a file
  • include/require that file

So, the informations that are relevant for the opcode cache (full path to the file, and the fact that it is included/required) are still here.

In consequence, autoload shouldn't bring any trouble with op code caching.

(And, when using APC, it doesn't, as far as I can tell)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文