gpt4 book ai didi

PHP5 框架 : Autoloading and Opcode Caching

转载 作者:可可西里 更新时间:2023-10-31 22:50:18 24 4
gpt4 key购买 nike

许多框架利用 spl_autoload_register() 来动态加载类(即 Controller 和模型)。有几篇关于自动加载和操作码缓存问题的帖子。特别是一篇帖子有@cletus 的回复,其中引用了@Rasmus 做出的一些陈述,这些陈述被证明对那些使用 APC 作为操作码缓存的人来说是令人讨厌的:

对于不影响操作码缓存性能的自动加载的任何可能替代方案,似乎没有任何讨论。

有没有办法解决自动加载类未添加到字节码缓存的问题?

如果没有,是否有任何替代方法可以动态加载将被缓存的类?

最佳答案

关于这个主题似乎仍然存在混淆,但在大多数情况下,它归结为易用性和性能。

Zend Frameworks 邮件列表中的这个邮件列表线程是一个不错的阅读主题:

http://n4.nabble.com/ZF-and-Autoloading-td640085i20.html

Now, the correlation is here because if you inherit from not-yet-defined class, you might rely on autoload to define it (though you might also rely on include), and actually the presence of the autoload facility may encourage you to use such inheritance. But this is not the autoload which brings trouble (see after Ramus' "it's not just autoload" in the blog for some examples of troublesome things). So the right phrase would be "people which tend to rely on autoload tend also to use code which defies compile-time binding". Which can't be seen as autoload fault, of course, and just avoiding autoload won't help a bit with that - you would also have to rewrite your code so that compile-time binding could happen. And it has nothing to do with uses of autoload with "new", for example.

As for the slowdown from the effects described above - i.e., absence of the compile-time binding - the code indeed becomes a bit slower and such code can lead in some obscure cases to some trouble to opcode caches (not in the autoload cases - but in cases where classes are defined inside conditions, or, God forbid, different definition is created depending on condition) - but it has next to nothing to do with using autoload by itself. The amount of slowdown, however, seem to be greatly exagerrated by people - it is nothing (and I repeat to be clear - NOTHING) compared to the performance benefit given by the opcode cache due to the absence of the disk operations and compilation stage. You could probably compose an artificial benchmark that would show some significant slowdown, but I do not believe any real application would even notice.

source: http://n4.nabble.com/ZF-and-Autoloading-td640085i20.html#a640092

关于PHP5 框架 : Autoloading and Opcode Caching,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1941541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com