Question

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 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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top