重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
在德兴等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站制作、成都做网站 网站设计制作按需规划网站,公司网站建设,企业网站建设,品牌网站建设,成都营销网站建设,成都外贸网站建设公司,德兴网站建设费用合理。
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
$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
//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."
";
//replace data
$mem->replace('key1','this is replace value',0,60);
$val =$mem->get('key1');
echo "Getkey1 value:".$val."
";
//save datagroup
$arr =array('aa','bb','cc');
$val = $mem->get('key1');
echo "Getkey1 value:".$val."
";
//replace data
$mem->replace('key1','this is replace value',0,60);
$val =$mem->get('key1');
echo "Getkey1 value:".$val."
";
//save datagroup
$arr =array('aa','bb','cc');
$mem->set('key2',$arr,0,60);
$val2 =$mem->get('key2');
echo "Getkey2 value:";
print_r($val2);
echo"
";
//delete data
$mem->delete('key1');
$val=$mem->get('key1');
echo "getkey1 value:".$val."
";
//closeconnetions
$mem->close();
?>
验证:
现在就成功了。
memcached查看所有key方法: