views:

30

answers:

2

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.

+2  A: 

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.

Chris Henry
+1  A: 

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.

timdev
We're using memcache for application caching. Unfortunately it's not available in config.php, so the workaround becomes a bit clunkier I think. Good idea though!
Owen
If it were possible to move your cache configuring up in your bootstrap process, memcache would be an *ideal* place to keep these data. If that's not possible, that's too bad. You could consider dedicated a small shared memory data cache in each APC instance, but with memcache in the mix, that just seems odd. OTOH, Chris Henry's note about `apc_compile_file` seems like it could do just what you want.
timdev