Ubuntu server 安装Memcache:
1.sudo apt-get update
2.安装Memcached服务端
<span style="font-size:18px;">sudo apt-get install memcached</span>
3.安装Memcache客户端
<span style="font-size:18px;">sudo apt-get install php5-memcache</span>
4.开启Memcached
memcached -d -m 128 -u root -p 11211
-d 开启 -m使用的内存大小 -u 用户名 -p Memcache使用的端口
5.重启apache : sudo service apache2 restart
6.memcache使用
<span style="font-size:18px;">//实例化一个Memcache对象
$mem = new Memcache;
//链接Memcache
$mem->connect('localhost', 11211);
//设置值
$mem->set('key', 'value', 0, 30); //0压缩模式 30失效时间</span>
<span style="font-size:18px;">echo $mem->get('key'); //获取值</span>
<span style="font-size:18px;">//删除数据</span>
<span style="font-size:18px;">$mem->delete('key');</span>
<span style="font-size:18px;">//替换数据</span>
<span style="font-size:18px;">$mem->replace('key', 'this is replace value', 0, 30);</span>
<span style="font-size:18px;">//清楚所有数据</span>
<span style="font-size:18px;">$mem->flush();</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">//关闭链接</span>
<span style="font-size:18px;">$mem->close();</span>
<span style="font-size:18px;">
</span>