您好,登錄后才能下訂單哦!
memcache-2.2.6.tgz ------------------memcache的php擴展
memcached-1.4.13.tar.gz ----------------------memcache服務端軟件
安裝memcached
安裝該軟件時需要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
啟動memcached:
memcached -d -m 10 -u root -l 0.0.0.0 -p 12000 -c 256-P /tmp/memcached.pid
驗證memcached:
ps -ef|grep mem
netstat -tnulp|grep mem
關閉memcached
cat /tmp/memcached.pid
949
kill -9 949
安裝php的memcache擴展
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
測試memcache的php擴展是否安裝成功
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擴展就成功了
memcache與php的配合使用
php與memcache結合測試代碼
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();
?>
驗證:
現在就成功了。
memcached查看所有key方法:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。