简体   繁体   English

Symfony2:使用OPcache进行编译的类

[英]Symfony2: class to compile with OPcache

In Symfony2, in the extension file of a bundle, it is possible to call: 在Symfony2中,在捆绑软件的扩展文件中,可以调用:

$this->addClassesToCompile([class1, ....])

This adds the given files to the cached file classes.php => this can improve performances if we put here the most used classes, because the PHP process only have to find and process 1 file insteaf many. 这会将给定的文件添加到缓存的文件classes.php =>中,如果我们将最常用的类放在此处,则可以提高性能,因为PHP进程只需查找并处理多个文件即可。

But with the 5.6 version of PHP, there is OPcache that can also cache files and also precompile them. 但是在PHP 5.6版本中,有OPcache可以缓存文件并对其进行预编译。 So I guess that the Symfony part isn't necessary anymore? 所以我猜想Symfony不再需要了吗?

By using a byte code cache PHP itself will cache the classes separately from the bootstrapped cache file. 通过使用字节码缓存,PHP本身将与自举缓存文件分开缓存类。 APC is already used for years to achieve this. APC已经使用了多年来实现这一目标。 PHP5.5 included the OPcache by default to do handle the opcache. PHP5.5默认包含OPcache来处理opcache。 Where APC also enabled users to easily add cache items itself, the OPcache is not available for users. APC还使用户能够轻松地自己添加缓存项,而OPcache对用户不可用。

Because of that, APCu was split from the original APC library so the traditional user caching becomes available for > PHP5.4. 因此, APCu与原始APC库分离,因此传统的用户缓存可用于> PHP5.4。 More info about Symfony performance can be found in The Book's performance chapter . 有关Symfony性能的更多信息,请参见《书》的性能一章

To answer your question about the Symfony bootstrap: If you use both the bootstrap caching and a bytecode cache, then adding files to the bootstrap will result into a bigger bytecode cache file. 要回答有关Symfony引导程序的问题:如果同时使用引导程序缓存和字节码缓存,则将文件添加到引导程序将导致更大的字节码缓存文件。 If your application has classes (like kernel.request listeners) that are used in every request, adding them to the bootstrap makes sense. 如果您的应用程序具有在每个请求中使用的类(例如kernel.request侦听器),则将它们添加到引导程序中就很有意义。 Otherwise it will only add overhead to, and will it marginally slow down all other requests. 否则,它只会增加开销,并且会稍微减慢所有其他请求的速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM