memcache的官方主页:http://pecl.php.net/package/memcache
memcached的官方主页:http://pecl.php.net/package/memcached
以下是我安装Memcached版本的PHP模块的过程记录:
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
在php.ini中加入
extension=memcached.so
完成
另:
在安装libmemcached时,如果只用./configure,可能会提示:
checking for memcached… no
configure: error: “could not find memcached binary”
两者使用起来几乎一模一样。
复制代码 代码如下:
$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');
复制代码 代码如下:
Memcache.hash_strategy =consistent
Memcache.hash_function =crc32
复制代码 代码如下:
$md->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
$md->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);
或
$mem->setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
以上就介绍了Memcached php的memcached客户端memcached,包括了Memcached方面的内容,希望对PHP教程有兴趣的朋友有所帮助。