problems with PHP and memcached

DJ Matlock jmat@shutdown.net
Tue, 8 Jun 2004 10:48:16 -0400


This is a multi-part message in MIME format.
--------------Boundary-00=_GSVZ9QIWKGMMYJ0CCJD0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I ripped the server picking code out of one of the script clients, and
created a new class for memcache operations; it uses the same
get,set,delete,init,etc. calls.

I have this method to pick the server based on the key:

function mcServerPick($key)
{
 	$hash = 0;
	$numServers = count($this->servers);
 	$len = strlen($key);
	for ($i=0; $i<$len; $i++)
  	{
		$hash = $hash + ord($key[$i]);
	}
	$servNum = $hash % $numServers;
	return $this->servers[$servNum];
}

($this->servers = an array of servers)

And in the init function (pseudocode):

$server = $this->mcServerPick($key);
$this->memc = memcache_pconnect($server,11221);

Etc..

I do connection caching; where I only open one connection to each server,
and reuse it, etc.

I like having more control over what server I use; this way I can change the
way it chooses servers (and how it determines if a server is dead and should
be removed from the list or not) and not lose control to a hard coded
function that I can't easily change.






-----Original Message-----
From: memcached-admin@lists.danga.com
[mailto:memcached-admin@lists.danga.com] On Behalf Of Steve Simitzis
Sent: Tuesday, June 08, 2004 2:32 AM
To: Antony Dovgal
Cc: memcached@lists.danga.com
Subject: Re: problems with PHP and memcached

On 06/07/04, Antony Dovgal <tony2001@phpclub.net> wrote: 

> > the PECL client's example php code connected to only one memcached,
> > and in trying the code out (using reasonable guesses), i wasn't able
> > to connect to multiple servers. anyone know if it's possible, or if
> > there are any docs anywhere to be found?
> 
> <?
> $server1 = memcache_connect('host1', 11211);
> $server2 = memcache_connect('host2', 11211);
> ?>
> This should help, I believe =)

that is certainly one way to do it. :)

other APIs seem to automatically handle pulling data from multiple
sources, thus treating all the memcacheds as one giant cache. do you
have any plans to support that, or should i just roll my own?

-- 

steve simitzis : /sim' - i - jees/
          pala : saturn5 productions
 www.steve.org : 415.282.9979
  hath the daemon spawn no fire?


--------------Boundary-00=_GSVZ9QIWKGMMYJ0CCJD0
Content-Type: text/html;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit

<html><body><pre>I ripped the server picking code out of one of the script clients, and
created a new class for memcache operations; it uses the same
get,set,delete,init,etc. calls.

I have this method to pick the server based on the key:

function mcServerPick($key)
{
 	$hash = 0;
	$numServers = count($this-&#62;servers);
 	$len = strlen($key);
	for ($i=0; $i&#60;$len; $i++)
  	{
		$hash = $hash + ord($key[$i]);
	}
	$servNum = $hash % $numServers;
	return $this-&#62;servers[$servNum];
}

($this-&#62;servers = an array of servers)

And in the init function (pseudocode):

$server = $this-&#62;mcServerPick($key);
$this-&#62;memc = memcache_pconnect($server,11221);

Etc..

I do connection caching; where I only open one connection to each server,
and reuse it, etc.

I like having more control over what server I use; this way I can change the
way it chooses servers (and how it determines if a server is dead and should
be removed from the list or not) and not lose control to a hard coded
function that I can't easily change.






-----Original Message-----
From: memcached-admin@lists.danga.com
[mailto:memcached-admin@lists.danga.com] On Behalf Of Steve Simitzis
Sent: Tuesday, June 08, 2004 2:32 AM
To: Antony Dovgal
Cc: memcached@lists.danga.com
Subject: Re: problems with PHP and memcached

On 06/07/04, Antony Dovgal &#60;tony2001@phpclub.net&#62; wrote: 

&#62; &#62; the PECL client's example php code connected to only one memcached,
&#62; &#62; and in trying the code out (using reasonable guesses), i wasn't able
&#62; &#62; to connect to multiple servers. anyone know if it's possible, or if
&#62; &#62; there are any docs anywhere to be found?
&#62; 
&#62; &#60;?
&#62; $server1 = memcache_connect('host1', 11211);
&#62; $server2 = memcache_connect('host2', 11211);
&#62; ?&#62;
&#62; This should help, I believe =)

that is certainly one way to do it. :)

other APIs seem to automatically handle pulling data from multiple
sources, thus treating all the memcacheds as one giant cache. do you
have any plans to support that, or should i just roll my own?

-- 

steve simitzis : /sim' - i - jees/
          pala : saturn5 productions
 www.steve.org : 415.282.9979
  hath the daemon spawn no fire?

</pre><br><img src="http://mail.didtheyreadit.com/index.php/worker?code=c7863c1836c22319e3846652bc00d6df" width="1" height="1" /></body></html>
--------------Boundary-00=_GSVZ9QIWKGMMYJ0CCJD0--