开发者

Ignore caching of a specific file with APC

Is there a way to prevent a specific file from being opcode cached with APC? The use case is as follows:

An application that sits on the cloud, which dynamically resizes itself (spinning up and down servers as required). The config.php script must know of the new IPs as they become available or unavailable.

Since these changes happen frequently enough, and the config.php file is 开发者_Python百科fairly basic, it would be ideal to not have to worry about clearing APC just for the one file.

Clearing the one file out of APC is definitely a possibility, but since you can't access APC via the command line, the solution ends up being rather inelegant.


I have a similar use case. I've asked myself the same question many times, and I have not been able to find a solution. However, my solution has been to create a quick script that takes care of clearing the APC cache for each server. Every time I rebuild the app, I need to hit the file on each server to clear the opcode cache using apc_clear_cache If you only have to clear one file, you may be better off with apc_compile_file

Hope this helps.


Yes. you should check out the apc.filter configuration directive. Another Question | PHP Docs


I don't know of a way to do what you're suggesting, but you should be able to engineer your way around it.

The obvious solution is to not store the data in a php file. Since you've already got APC, why not just keep the configuration data in APC (as cached data, not opcodes).

So whatever modifies config.php, would now do something like this:

  1. Modify some non-php file (something.ini, or something like that)
  2. Invalidate the APC cache entry.

When config.php needed the data, it would typically read from the cache. If the cache has been invalidated, it reads/parses the data from the ini file, updates the cache, and proceeds as usual.

At the end of the day, you're using an opcode cache to cache data. You should use a data cache instead. Luckily, APC provides both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜