开发者

APC and PHP - Broken Sites Due to Cache Mixing

开发者 https://www.devze.com 2023-02-25 21:50 出处:网络
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 to

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 wordpres开发者_JAVA技巧s 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


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 :)


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

  • apc.canonicalize (If on, then relative paths are canonicalized in no-stat mode.)
  • apc.preload_path (No idea, really...)

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


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?


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'));
}


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 :)


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 :)


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消