7

How would I use the apc.filters parameter in APC opcode caching to not cache certain paths? For example, I want caching to be active for anything under the path:

"/var/www/vhosts"

and exclude paths like

"/usr/share/psa-horde/"

I tried using

apc.cache_by_default = 0
apc.filters = "+/var/www/vhosts"

and

apc.cache_by_default = 1
apc.filters = "-/usr/share/psa-horde/"

But neither worked as I expected.

http://www.php.net/manual/en/apc.configuration.php#ini.apc.filters

Should the filter be something more like "+/var/www/vhosts/*" (note the wildcard)? I'm afraid this isn't possible because of the way filters works:

Note that the filename used for matching is the one passed to include/require, not the absolute path.

Any ideas or sample configurations?

typeoneerror
  • 55,990
  • 32
  • 132
  • 223

5 Answers5

6

The filter should be a comma separated list of POSIX extended regular expressions. I believe what you have in the second attempt only matches the exact path /usr/share/psa-horde/, and not /usr/share/psa-horde/something or /usr/share/psa-horde/anotherfile.php

The following should match anything in the sub folder

apc.filters = "-/usr/share/psa-horde/.*"
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
  • Hmm, good call, but I think it only works for the file name if the full path was used in the require statement: "Note that the filename used for matching is the one passed to include/require, not the absolute path." – typeoneerror Oct 27 '09 at 03:51
  • e.g. tried "-/var/www/vhosts/myhostname.com/svn/public/openx/.*" and files in this directory are still being cached. – typeoneerror Oct 27 '09 at 03:51
  • "Note that the filename used for matching is the one passed to include/require, not the absolute path." - from docs – livelygreen Nov 22 '11 at 16:21
  • I don't understand this exact phrase.. what path should he use instead of "-/var/www/vhosts/myhostname.com/svn/public/openx/.*" ? – MultiformeIngegno Dec 30 '12 at 15:26
5

A very late response, but just in case someone else is having this issue (I'm going to guess you may be/have been running a Plesk box, which is why I came across this).

Your best bet is to have APC in the list of loaded php modules, but have apc.enabled 0 in the master php.ini. Then, for each vhost you want to have it enabled for, add php_admin_value apc.enabled 1 to enable for each. Could be an issue if you have a ton of sites, but works for just a few.

pnomolos
  • 836
  • 12
  • 15
2

pnomolos' solution works if you have different vhosts, but it won't work if you have only one and want to control caching on a truly per-directory basis.

This bug report points to the best the solution : https://bugs.php.net/bug.php?id=57064

Enable APC and set apc.cache_by_default to 0 in php.ini. In your Apache config, you can then use php_admin_setting apc.cache_by_default 1 inside a Directory block to enable APC caching exactly where you need it.

jcharaoui
  • 221
  • 2
  • 4
0

Used:

apc.filters="-/eliminate/path1/,-/eliminate/path2/,+/add/to/cache/"
kleopatra
  • 51,061
  • 28
  • 99
  • 211
0

Since apc.filters works with regular expressions, wildcard path should be specified as apc.filters = "-/usr/share/psa-horde/.*"