Official homepage of memcache: Http://pecl.php.net/package/memcache
Official homepage of memcached: http://pecl.php.net/package/memcached
The following is a procedure record of the PHP module that I installed memcached version of:
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-c/local/webserver/php/bin/php-config--with-libmemcached-dir=/usr/local /libmemcached
Make
Make install
Join in the php.ini
Extension=memcached.so
Complete
Other:
When installing libmemcached, if you use only./configure, you may be prompted:
Checking for memcached ... no
Configure:error: "Could not find memcached binary"
They are almost identical in use.
Copy the Code code as follows:
$mem = new Memcache;
$mem->addserver ($memcachehost, ' 11211 ');
$mem->addserver ($memcachehost, ' 11212 ');
$mem->set (' HX ', ' 9enjoy ');
echo $mem->get (' HX ');
Copy the Code code as follows:
$MD = new Memcached;
$servers = Array (
Array ($memcachehost, ' 11211 '),
Array ($memcachehost, ' 11212 ')
);
$MD->addservers ($servers);
$MD->set (' HX ', ' 9enjoy ');
echo $md->get (' HX ');
memcached more than memcache, such as getmulti,getbykey,addservers and so on.
Memcached does not have a Memcache connect method and currently does not support long connections.
Memcached supports Binary Protocol, and Memcache does not support it, which means that memcached will have higher performance.
Memcache is a native implementation, support OO and non-oo two sets of interfaces coexist, memcached is the use of libmemcached, only support OO interface.
A 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's distribution algorithm generally has two options:
1, according to the result of the hash (key), the remainder of the modulus connection determines which node to store, that is, the hash (key)% sessions.size (), the algorithm is simple and fast, good performance. However, this algorithm has a disadvantage, that is, when the memcached node is added or deleted, the original cache data will be large-scale failure, the hit rate is greatly affected, if the number of nodes, cache more data, the cost of rebuilding the cache is too high, so there is a second algorithm.
2, consistent Hashing, the consistent hashing algorithm, his lookup node process is as follows:
The hash value of the memcached Server (node) is first calculated and configured on the 0~232 Circle (Continuum). It then uses the same method to find the hash value of the key that stores the data and maps it to the circle. It then searches clockwise from where the data is mapped, saving the data to the first server found. If the server is still not found after 2 32, it will be saved to the first memcached server.
Memcache in the case of no configuration, the first method is used. Memcached to implement the first method, it seems to be used (not confirmed):
$MD->setoption (Memcached::opt_hash, MEMCACHED::HASH_CRC);
The second consistent hashing algorithm:
Memcache in PHP.ini
Copy the Code code as follows:
Memcache.hash_strategy =consistent
Memcache.hash_function =CRC32
Memcached in the program (not confirmed)
Copy the Code code as follows:
$MD->setoption (memcached::opt_distribution, Memcached::D istribution_consistent);
$MD->setoption (Memcached::opt_hash, MEMCACHED::HASH_CRC);
Or
$mem->setoption (memcached::opt_distribution,memcached::D istribution_consistent);
$mem->setoption (memcached::opt_libketama_compatible,true);
Some reference documents:
memcached Distribution test Report (hash function selection in the case of consistent hashing):
http://www.iteye.com/topic/346682
PHP module Memcache and memcached differences: http://www.jb51.net/article/27366.htm
PHP Modules: Memcached > memcache:http://www.jb51.net/article/27367.htm
20110509@ @UPDATE:
If the installation libmemcached has the following error prompt:
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
--disable-64bit cflags= "-o3-march=i686" can be added at configure
i.e.:./configure--prefix=/usr/local/libmemcached--with-memcached--disable-64bit cflags= "-o3-march=i686"
The above describes the memcached php memcached client memcached, including the memcached aspects of the content, I hope that the PHP tutorial interested in a friend helpful.