php - Use memcache for different domains (the same keys) on one server -


i have situation: have 2 sites on 1 server - , use same frameworks (based on codeigniter framework). , in code use memcache like

    $memcache = new memcache;     $memcache->connect('localhost', 11211);     $value = $memcache->set('max_id', 100500); 

and in case when change value on site1 have value site2, need different values different sites.

off course can replace keys, adding site_url() so:

$value = $memcache->set(base_url() . 'max_id', 100500); 

but maybe exist better solution ?

i found solution: create new class, inherited memcache , use on sites class.

class site_memcache extends memcache {     private $_prefix = '';      public function __construct()     {         $this->_prefix = $_server['http_host'];     }      public function set($key, $var, $flag = null, $expire = null)     {         parent::set($this->_prefix . $key, $var, $flag, $expire);     }      public function get($key, &$flags = null)     {         return parent::get($this->_prefix . $key, $flags);     }      public function delete($key)     {         return parent::delete($this->_prefix . $key);     } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -