8

I hope someone can give me a hand figuring this out. I have been running APC recently on some of my servers that host only one application and it's been working great. Unfortunately I went to run it tonight on my workhorse web server and as soon as I turned it on I started getting 'mixing' from my wordpress blogs. The first blog to get loaded would cache database information and then every blog loaded later would get a database error.

What I want to know is if there is a way to prefix the cache somehow so that I can avoid this problem. I assumed that the cache would respect the differences in absolute pathing between the files and not use the same cached copy on multiple sites... FAIL

Thanks in advance!

Update

As requested here is a copy of the apc.ini file that I use in /etc/php.d/ to override default settings:

/etc/php.d/apc.ini

extension=apc.so
apc.shm_size                    = 64M
apc.max_file_size               = 8M
apc.include_once_override       = 1
apc.stat_ctime                  = 1
Shane
  • 16,779
  • 5
  • 27
  • 46
  • Haven't used APC, but in memcached you can set a prefix. We usually set a clean url as the prefix. I'm sure APC has that as well. – JohnP Apr 17 '11 at 05:29
  • @JohnP: "you can set a prefix" --- uhm, how? – zerkms Apr 17 '11 at 06:02
  • @zerkms whoops sorry, I forgot we were using Zend ^_^ The prefix is set in the wrapper. foot> – JohnP Apr 17 '11 at 06:15
  • Ahh, got my hopes up there for a moment. Well, I have disabled APC until I can figure this out. I am running this on a very slimlined server so an opcode cache would be a huge benefit since these are mainly static sites and/or wordpress blogs. Any help is appreciated! – Shane Apr 17 '11 at 18:26
  • @Flask - I only alter a few of the system defaults. I will append the settings to my main question. – Shane May 11 '11 at 17:38
  • 4
    Important: are you seeing a mixing of *user* cache entries, or *system* cache entries? If user cache entries are being mixed, then the user code needs to be modified to prefix all calls with a site-specific identifier. If you're seeing problems with *system* cache entries, make sure that APC isn't filling up. I see issues with APC corruption frequently if the cache fills. Check utilization with the bundled `apc.php` script, and if you fill the cache/fragment, then increase your APC memory limit. – Frank Farmer May 13 '11 at 22:52
  • I am seeing system cache entries being mixed. I am not using user cache at all in my setup. Basically what happens is when I restart apache the first website I hit gets cached and then all other requests to other Wordpress sites on my server load from the first servers cache (so you see the WRONG website). – Shane May 17 '11 at 17:19

7 Answers7

6

As far as i knnow you cannot use global settings to set prefix for different applications. You could change your key names and add prefix to its names. If youre more skilled you could use two different instances of php using fastcgi, depending on what http server youre using. We're doing something like that using APC and ngix :)

kkszysiu
  • 537
  • 2
  • 8
4

Have you tried setting apc.file_md5 to On? Other directives that might make a difference:

Depending on your objective, I believe that either apc.file_md5 or apc.canonicalize will help.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
  • 1
    I am going to look into this tonight if I can and see if it fixes my issue. Sounds promising, especially the canonicalize and MD5. Thanks! – Shane May 17 '11 at 17:20
2

Is wordpress adding the cache entries to save DB requests? If so you will need to edit the cache library file to include a prefix.

I am guessing you are using a wordpress plugin? If so which plugin?

instigator
  • 1,587
  • 5
  • 15
  • 27
2

If you're using the Doctrine ORM and have enabled APC caching without specifying a prefix this could cause problems.

In my case, using the Symfony framework and blindly following the guide at http://symfony-check.org/ led to APC cache mixing.

Thanks to the guys at Apostrope Now https://groups.google.com/d/msg/apostrophenow/1Z79wc4wjQk/6Vi2jLjP-twJ it seems you need to specify a unique prefix to the Doctrine cache.

/config/ProjectConfiguration.class.php

public function configureDoctrine(Doctrine_Manager $manager)
{
  $manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, new Doctrine_Cache_Apc(array('prefix' => 'something_unique'));
}
Peter Hough
  • 560
  • 4
  • 17
1

Have you already tried the memory mapping? It seems (I'm going to try it!) it should work fine and, using php-fpm and the pools, it allows you to have different accounts with different caches...!
Here's a link that could interest you: http://ravirajsblog.blogspot.it/2012/02/php-apc-locking-mechanism.html :)

Alessio Periloso
  • 109
  • 2
  • 12
0

I just had to deal with this issue.. I added the following apc params

apc.file_md5 = 1
apc.canonicalize = 0 

Not sure if that helped or the variable I added to the file. In my case however it was mixing up files under one web root, that happened to exist in different paths, have the same name and the same "header".

Ahmad
  • 59
  • 1
0

I have module, which can help you: http://github.com/jamm/memory
There you can use prefixes, tags for keys and other benefits.
And you can change cache storage (APC, memcache, shm-memory) without changing your code (one interface for all storages).

edit: it's for user's cache, so it's will not fix your issue. You mentioned it late :)

OZ_
  • 12,492
  • 7
  • 50
  • 68