I have a webserver with lots of sites which are all based on Drupal. The sites share a vast majority of identical code, and it'd be great if APC could take advantage of this and not 're-cache' the same files x times over.

Is there any theoretical problem with this idea? Do any PHP opcode caches take advantage of this that you know of?


Seems the answer's no, at least as things currently stand.


apc.file_md5 does not solve the duplication problem because it doesn't identify the cached files. See question What does apc.file_md5 do (Alternative PHP Cache)?

To avoid duplication, perhaps symlinking some Drupal directories could work. So, instead of

/vhost1/drupal/includes/(a lot of files)
/vhost2/drupal/includes/(a lot of files)

you could have

/vhost1/drupal/includes => /path/to/drupal-master/includes/
/vhost2/drupal/includes => /path/to/drupal-master/includes/

Be aware that all Drupal instances running with this trick must be the same version... if not, bad things may happen ;-P

  • 1
    Thanks, yeah that other question is also mine! The problem with symlinking, as you say, is that you need to use the same code. This can cause problems not only because of different versions, but also patches, and basically would require quite a major rethink to our current deployment process. That's exactly why I was hoping I could offload the whole problem onto APC. That way the development workflow still treats each site as entirely separate, but where there are identical files they don't each get cached separately. – Andy Oct 25 '12 at 12:12
  • Yes, I'm looking to a solution for this too. But be aware that APC identifies files by name, and detects changes with the files' mdate, so de-duplication must be done after storing files and comparing one file's md5sum to everyone other. I don't know if someone is working on this, but for sure it's a tough problem. – Isra Oct 27 '12 at 19:35
  • After all, big websites that require deep optimization have a dedicated server and don't share resources with anyone other, so don't expect Facebook to publish a killer APC fork on this point :-P – Isra Oct 27 '12 at 19:37

You should post your APC runtime config. Have you tried setting 'apc.file_md5' on to help? Docs are scarce on this option, but it sounds like what it would do is MD5 cache the files and (hopefully) compare them instead of relying on the real path to the files...

  • Thanks, I hadn't seen apc.file_md5. I've updated to APC-3.1.5 (I was on most recent stable, 3.0.19) and set apc.file_md5=1: no joy on my minimal test with two identical pages :/ – Andy Nov 14 '10 at 15:48
  • 1
    apc.file_md5 is not (in and of itself) a solution it turns out - see this Q – Andy Nov 17 '10 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.