您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。