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->SaddServer($meache,hosts,host '11211');
$mem->addServer($memcachehost, '11212');
$mem->set('hx','9enjoy');
echo $mem->get( 'hx');
複製程式碼 程式碼如下:
$md 🎜>$servers = array(
array($memcachehost, '11211'),
array($memcachehost, '11212')
);
$md->addServers($servers);
$md->set('hx','9enjoy');
echo $md->get('hx');
複製程式碼 程式碼如下:
Memcache.hash_strategy =consistent> hash_function =crc32
memcached在程式中加(未確認)
複製程式碼 程式碼$md->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); $md->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC_CRC);
或$m- >setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
一些參考文件:
memcached分佈測試報告(一致性雜湊情況下的雜湊函數選擇):
http://www.iteye.com/topic/346682
php模組memcache和memcached區別:http://www.jb51.net/article/27366.htm
PHP模組:Memcached > Memcache:http://www.jb51.net/article/27367.htm
20110509@@ UPDATE:
如果安裝libmemcached有以下出錯提示:
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
可在configure時增加--disable-64bit CFLAGS="-O3 -march=i686"
即:./configure --prefix=/usr/local/libmemcached --with-memcached --disable-64bit CFLAGS="-O3 -march=i686"
以上就介紹了Memcached php的memcached客戶端memcached,包含了Memcached方面的內容,希望對PHP教程有興趣的朋友有所幫助。