简体   繁体   中英

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.

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

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:

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.

Debugging

After @hakra pointed out to me the behaviour of APC, I was able focus my efforts on the class loader . My class loader uses memcached as cache for storing the class paths. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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