php memcached client memcached

  • 2020-05-07 19:24:53
  • OfStack

memcache official homepage: http: / / pecl php. net/package/memcache
memcached official homepage: http: / / pecl php. net/package/memcached

The following is the record of my installation of Memcached version of PHP module:

wget http://download.tangent.org/libmemcached-0.48.tar.gz
tar zxf libmemcached-0.48.tar.gz
cd libmemcached-0.48
./configure --prefix=/usr/local/libmemcached --with-memcached
make
make install

wget http://pecl.php.net/get/memcached-1.0.2.tgz
tar zxf memcached-1.0.2.tgz
cd memcached-1.0.2
/usr/local/webserver/php/bin/phpize
./configure --enable-memcached --with-php-config=/usr/local/webserver/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
make
make install

Add in php.ini
extension=memcached.so
complete

The other:
When installing libmemcached, if you only use./configure, you may be prompted:
checking for memcached... no
configure: error: "could not find memcached binary"

Both work almost exactly the same.
 
$mem = new Memcache; 
$mem->addServer($memcachehost, '11211'); 
$mem->addServer($memcachehost, '11212'); 
$mem->set('hx','9enjoy'); 
echo $mem->get('hx'); 

 
$md = new Memcached; 
$servers = array( 
array($memcachehost, '11211'), 
array($memcachehost, '11212') 
); 
$md->addServers($servers); 
$md->set('hx','9enjoy'); 
echo $md->get('hx'); 

memcached has many more methods than memcache, such as getMulti, getByKey, addServers, etc.
memcached does not have memcache's connect method and does not currently support long connections.
memcached supports Binary Protocol, while memcache does not, which means memcached will have higher performance.
Memcache is a native implementation that supports both OO and non-OO interfaces, while memcached USES libmemcached and only supports OO interfaces.
More detailed distinction: http: / / code google. com p/memcached/wiki/PHPClientComparison


The memcached server is a centralized caching system, and the distributed implementation method is determined by the client.
memcached distribution algorithm 1 has two choices:
1. According to the results of hash(key), the remainder of the number of modular connections determines which node to store, namely hash(key)% sessions.size (). This algorithm is simple, fast and performs well. However, there is a disadvantage of this algorithm, that is, when the memcached node is added or deleted, the original cache data will be invalid on a large scale, and the hit ratio will be greatly affected. If the number of nodes is large, the cache data is large, and the cost of cache reconstruction is too high, so the second algorithm is adopted.
2. Consistent Hashing, 1 unique hash algorithm, its node search process is as follows:
        first finds the hash value of memcached server (node) and configures it to the circle (continuum) of 0 ~ 232. The hash value of the key storing the data is then calculated in the same way and mapped to the circle. Then start a clockwise search from where the data is mapped to, saving the data to the first server found. If the server cannot be found beyond 2 to the 32, it will be saved to the first memcached server.

memcache USES the first method without any configuration. To implement the first method, memcached appears to use (not confirmed) :
$md- > setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);    

The second kind of 1 - induced hash algorithm:

memcache is added to php.ini
 
Memcache.hash_strategy =consistent 
Memcache.hash_function =crc32 

memcached in the program (not confirmed)
 
$md->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); 
$md->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC); 
 or  
$mem->setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT); 
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true); 

1 some reference documents:
memcached distribution test report (hash function selection in the case of 1 uniqueness hash) :
http://www.iteye.com/topic/346682
php module memcache and memcached difference: / / www ofstack. com article / 27366. htm
PHP module: Memcached > Memcache: / / www. ofstack. com article / 27367. htm

20110509 @ @ UPDATE:
If libmemcached is installed, there is the following error message:
make[2]: *** [clients/ms_conn.o] Error 1
make[2]: Leaving directory `/www/soft/libmemcached-0.48'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/www/soft/libmemcached-0.48'
make: *** [all] Error 2

Can be added when configure -- disable-64bit CFLAGS=" -O3-march =i686"
./configure --prefix=/usr -- local/libmemcached -- with-memcached -- disable-64CFLAGS =" -O3-march =i686"

Related articles: