memcache and php server optimization

Roberto Spadim roberto at
Fri Jan 12 13:07:17 UTC 2007

i'm new to memcache, but i see some usefull thinks that could be implemented
see my php code:
    $memcache= new Memcache;
    $memcache->connect('',11211);   // only one server
    echo (microtime(1)-$st)."\n";   // ~0.0013 seconds (maybe 1 packet 
to and 1 packet from memcache)
    echo (microtime(1)-$st)."\n";   // ~0.0026 seconds (maybe 2 packets 
to and 2 packets from memcache)
only if we are sending two packets (i don't know memcache protocol):
    i think that sending only one packet with get two keys could be 
faster than two packets (i don't know if memcache server implements it)

now for set, add and replace:
$memcache->set( array($key1,$key2,$key3),'1');   // set all keys to 1 
(can make with only one packet?)
array($key1,$key2,$key3),array($value1,$value2,$value3));   // set each 
key for each value (i don't know if we could use only one packet, values 
can be very big... but keys don't!)

now for delete, allow arrays like:
    $memcache->delete( array($key1,$key2,$key3));   // could be done 
with only one packet too
today only this work:

now some feature requests, these functions should be only for one server!:
    $memcache->getkeyscount($host,$port);   // return keys count
    $memcache->getallkeys($host,$port);   // get ALL keys
    $memcache->getallkeys($host,$port,0,15);   // get keys from 0 to 15,
    // i don't know if we have an index of variables but  getallkeys 
with parameters could work with for:
    for ($i=0;$i<$memcache->getkeyscount();$i++){

i don't know memcache protocol very well but seeing time for one(0.0013) 
and two gets(0.0026) i think that we are sending many(2) packets, 
sending only one packet could be an optimization when we are connected 
with one server, many servers could allow too, but i don't know if cpu 
utilization or network utilization could be too high on each memcache server
thankx guys,
Roberto Spadim

More information about the memcached mailing list