3
votes

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.

1
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. - Ben
@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

1 Answers

5
votes

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);
?>