[announce] php: mcache extensions 1.1.0

John McCaskey johnm at klir.com
Fri Jan 28 09:26:12 PST 2005

On Fri, 2005-01-28 at 09:12 +0100, Per Wigren wrote:
> Hi!
> Thanks for the mcache extension, it's really great!

Thanks, I hope you don't mind my cc'ing this reply to the list as well,
but I thought that others might be interested in your set_domain()

> I have a simple feature request. If I run several sites (all
> controlled by me) it would be great to be able to set a memcache
> domain so the keys don't collide. For example.
> $mc->set_domain('mydomain');
> and from then on all keys will be prefixed by 'mydomain:' so
> $mc->set('mykey', $myvar); will set the key 'mydomain:mykey' and
> $mc->get('mykey'); will also get 'mydomain:mykey'..

The real solution to this is namespaces supported at the server/protocol
level, and this has been discussed as an upcoming feature for memcached
itself.  However, I do see the utility of this type of temporary
solution so I'll put it on my roadmap for the next release.  I would
probably change the syntax to set_namespace('mydomain'), as I expect
eventually that it what it will get called in the protocol, and if I'm
lucky the php api won't need to change to match up with the standard

> I also wonder how I can set_initialized(FALSE) from outside the PHP
> instance, for example when adding a server to the (potential *g*)
> cluster of memcached/tugelacache nodes..

This get's a little bit tricky as your webserver is keeping the
persistent object cache, so if you are using for example apache 1.3, or
apache 2.x in pre-fork mode, then you end up with one persistent object
per apache child process.  As such, the only way to access the object
and set_initialized(FALSE) is to call pmemcache('your_id') from within
that apache process.  Obviously this isn't going to work very easily, as
you'd have to do something like have a webpage that you hit manually,
but hit it repeatedly in an attempt to get it handled at least once by
each process.  Furthermore, if you set_initialized(FALSE) manually, you
shouldn't then just add all servers again, as it will result in some
servers being in the list twice, which is allowed by libmemcache.

I'd suggest a different method, use the timeout value that I made
optional, then when you add servers obtain the server list from your db,
or a config file, or wherever an up-to-date list of all servers will be.
Check this out:

  $mc = pmemcache('myobjectid', 600);

  if(!$mc->is_initialized()) {
     $servers = get_mc_server_list(); //function gets list from db or
     foreach($servers as $server) {
        $mc->add_server($server['host'], $server['port']);

   //do your normal gets/sets/whatever

The effect this has is that once every 10 minutes any persistent objects
will get reset and be updated with the current server list that you are
maintaining somewhere.  The performance impact of doing this is very low
as obviously it only occurs every 10 minutes.  You can tweak the timeout
to be whatever you like.

> Regards,
> Per Wigren
John A. McCaskey
Software Development Engineer
Klir Technologies, Inc.
johnm at klir.com

More information about the memcached mailing list