0

I am currently using APC with PHP FPM to cache a few hundred Wordpress sites. With a 2gig cache everything works well but it isn't terribly efficient and the cache is always maxed out.

If I have 200 Wordpress sites all on the same server all with identical versions, it will cache 200 identical wp-db.php files for example.

I seem to remember a discussion a few years back about how it could be a security risk. I doubt that is an issue any longer (especially with PHP FPM) but I control all the sites anyway so the benefits are better than any downsides.

Has this changed in recent years at all? Especially with the new default Zend Opcache? A hack like symlinks isn't ideal e.g. you can't upgrade 500 sites all at once so it would break horribly from time to time.

Nick
  • 287
  • 1
  • 10

1 Answers1

0

This is a partial response as I did not experience this with zend opcode.

Last time I used apc this feature hits me as a bug, never saw it as a feature :-). If you use chroot-ed pools with php-fpm and if all the pools have the same relative paths in the chroot, then they share the same cache key in apc. As the key is the full absolute file path, and in a chroot this file path cannot contain the part before the chroot.

So you could try it with chroot. But this implies several tricks:

  • the chroots should contain all elements that php could need (temporary directories, /etc/hosts, some devices)
  • php mail would not work and should be used in smtp mode
  • some files should be excluded from the cache, all the files containing settings, if you forget that point websites will get mixed up!
  • maybe some others, chroot is never simple
regilero
  • 1,470
  • 1
  • 9
  • 14
  • Yeah deliberate hash collisions will force it, but it won't achieve the ideal 'merge identical files, leave other files separate'. All the caches do lookup_key(hash(filename + filemtime)) where as the ideal method would be lookup_key(lookup_key(hash_file_contents(filename)) + filemtime) where the file contents are hashed, not the filename and the file hash is cached along with the last modified time. – Nick Sep 18 '14 at 03:58
  • In an ideal world the cache key would be a setting, with several options available (filename, mtime, md5, inode identifier...) – regilero Sep 18 '14 at 08:10