5

What's the best option for avoiding key collisions between multiple sites running on the same server using APC for user caching?

I've run into issues where 2 or more sites were using the same cache key and expecting different types of items to be stored under it--one expecting a json string, the other an array, another an object.

Is their a way to segment APC by site?

BTW: I'm using APC with Apache running prefork and mod_php.

Ray
  • 40,256
  • 21
  • 101
  • 138
  • I'm a bit confused as to why this was downvoted; it's a reasonable question, and one which I was looking for an answer too as well. I hadn't even thought of server variables (the answer), and it was helpful. On a site where a question asking to test if a number is negative has 300+ votes, I can't understand how this question was downvoted. – Jess Mar 27 '13 at 20:28
  • 1
    @mazzzzz it looks like a user upvoted it a while back, but SO deleted the user and took away they points which were awarded :/ – Ray Mar 28 '13 at 21:30

1 Answers1

6

Perhaps you could append the server hostname to the key, you could define a constant or create some model for handling your APC:

<?php 
define('APC_HOST_KEY',$_SERVER['HTTP_HOST']);

apc_store(APC_HOST_KEY.'_value_key', $value);
?>
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • This sound reasonable. Ideally I'd like to avoid adding a new non-standard function or require all coders on my team to ensure they prefix their keys--lots of chance for forgetful mistakes. However, this may be the only practical path. Still going to hang on for a bit to see if there's a super secret APC way to segregate the memory chunk. – Ray Nov 08 '12 at 15:03
  • All quiet, going to have to go your route – Ray Nov 09 '12 at 15:08