您好,登錄后才能下訂單哦!
memcache-2.2.6.tgz ------------------memcache的php擴(kuò)展
memcached-1.4.13.tar.gz ----------------------memcache服務(wù)端軟件
安裝memcached
安裝該軟件時(shí)需要libevent的支持,
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable/
./configure
make
make install
安裝 memcached
tar -zxvf memcached-1.4.11.tar.gz
cd memcached-1.4.11/
./configure --prefix=/usr/local/memcached--with-libevent=/usr
make
make install
啟動(dòng)memcached:
memcached -d -m 10 -u root -l 0.0.0.0 -p 12000 -c 256-P /tmp/memcached.pid
驗(yàn)證memcached:
ps -ef|grep mem
netstat -tnulp|grep mem
關(guān)閉memcached
cat /tmp/memcached.pid
949
kill -9 949
安裝php的memcache擴(kuò)展
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6/
/usr/local/php/bin/phpize
./configure --enable-memcache--with-php-config=/usr/local/php/bin/php-config
make
make install
接下來修改php配置文件php.ini
vi php.ini
extension=memcache.so
測(cè)試memcache的php擴(kuò)展是否安裝成功
memcached -d -m 10 -u root -l 0.0.0.0 -p 12000 -c 256-P /tmp/memcached.pid
/usr/local/apache/bin/apachectl start
cd /usr/local/apache/htdocs
vi mem_test.php
<?php
$mem=newMemcache;
$mem->connect("10.10.10.16",12000);
$mem->set('hello','world',0,60);
$val=$mem->get('hello');
echo $val;
?>
如果可以看到world,那你的memcachephp擴(kuò)展就成功了
memcache與php的配合使用
php與memcache結(jié)合測(cè)試代碼
cd /usr/local/apache/htdocs
vim php-mem.php
<?php
//connect
$mem = newMemcache;
$mem->connect('10.10.10.16',12000);
//save data
$mem->set('key1','this is first value',0,60);
$val =$mem->get('key1');
echo "Getkey1 value:".$val."<br/>";
//replace data
$mem->replace('key1','this is replace value',0,60);
$val =$mem->get('key1');
echo "Getkey1 value:".$val."<br/>";
//save datagroup
$arr =array('aa','bb','cc');
$val = $mem->get('key1');
echo "Getkey1 value:".$val."<br/>";
//replace data
$mem->replace('key1','this is replace value',0,60);
$val =$mem->get('key1');
echo "Getkey1 value:".$val."<br/>";
//save datagroup
$arr =array('aa','bb','cc');
$mem->set('key2',$arr,0,60);
$val2 =$mem->get('key2');
echo "Getkey2 value:";
print_r($val2);
echo"<br/>";
//delete data
$mem->delete('key1');
$val=$mem->get('key1');
echo "getkey1 value:".$val."<br/>";
//closeconnetions
$mem->close();
?>
驗(yàn)證:
現(xiàn)在就成功了。
memcached查看所有key方法:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。