简体   繁体   English

APC optcode缓存如何识别类?

[英]How does APC optcode cache identify a class?

I'm running a one instance Apache setup with multiple virtual hosts that runs different versions of the same code base. 我正在运行一个实例Apache设置,其中包含多个虚拟主机,这些虚拟主机运行同一代码库的不同版本。

By this I mean that one virtual host can server one version of a class and another can server second version of the same class (same namespace, same name). 我的意思是,一个虚拟主机可以为一个类的一个版本提供服务,而另一个虚拟主机可以为相同的类(相同的名称空间,相同的名称)提供第二个版本。

/file/path/host-a/MyClass.php
/file/path/host-b/MyClass.php

Sometimes I get an exception that shows me that one of the virtual hosts uses the "wrong" version of a class. 有时,我会看到一个异常,该异常向我显示其中一个虚拟主机使用的是“错误”版本的类。 Eg on host b I get an exception with file path to script of /file/path/host-a/MyClass.php 例如,在主机b上,我获得了/file/path/host-a/MyClass.php脚本的文件路径异常

I thought that the APC optcode cache used the file path, at least as a part of the key, but I'm fearing, that it only uses a qualified class name like: 我以为APC optcode缓存至少使用文件路径作为密钥的一部分,但我担心它仅使用合格的类名,例如:

My\Namespace\MyClass

Is that the case? 是这样吗 Please point to any documentation on this subject if possible. 如果可能,请指向有关此主题的任何文档。

Answer 回答

Though is was unable to find any documentation on the answer to this question php - APC opcode caching on different file versions explains that the APC optcode cache in fact does use the path of the file that defines the class to distinguis classes with the same name. 尽管无法找到有关此问题的答案的任何文档php- 不同文件版本上的APC操作码缓存说明, APC操作码缓存实际上确实使用了定义类的文件路径来区分具有相同名称的类。

Debugging 调试

After @hakra pointed out to me the behaviour of APC, I was able focus my efforts on the class loader . 在@hakra向我指出APC的行为之后,我就可以将精力集中在类加载器上 My class loader uses memcached as cache for storing the class paths. 我的类加载器使用memcached作为存储类路径的缓存。 It turned out that the code for building cache keys were the cause of the problem - and not the APC which it seemed to be. 事实证明,用于构建缓存键的代码是问题的原因-而不是它看起来的APC。

So should you be in a similar situation where your see that the incorrect "versions" of a class is loaded ensure that you class loader is working as expected. 因此,如果您在类似的情况下看到某个类的错误“版本”已加载,则应确保您的类加载器正在按预期方式工作。 One obvious clue is of course the file path of the problem class. 一个明显的线索当然是问题类的文件路径。

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

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