<span style="font-size:18px;"><?php //php作为客户端使用memcache
//memcache占内存所,占CPU少
//memcache是通过IP直接获取的数据的,没有任何的验证---不安全,轻则数据被人查看,重则服务器被攻击
//最好放到内网访问,不对外公开 memcache -d -u root -l 192.168.1.111 -p 11211 只允许111服务器访问
$mem=new Memcache();
$mem->connect("localhost", 11211); //connect持久链接
// $mem->addServer("www.lamp.com", 11221);
// $mem->addServer("192.167.1.112", 11211);
$mem->add("mystr", "this is a memcache test!", MEMCACHE_COMPRESSED, 3600);
//$mem->add("mystr", "this is a memcache test!", MEMCACHE_COMPRESSED, 3600);//这个值添加不进去,重复键名(memcache重复添加不了)
$mem->set("mystr", "wwwwwwwwwwwwww", MEMCACHE_COMPRESSED, 3600); //修改键名的值 也可以replace
$mem->delete("mystr");//删除单个
$mem->flush(); //删除所有
$str=$mem->get("mystr");//获取设置的值
echo "string: ".$str."<br>";
$mem->add("myarr", array("aaa", "bbb", "ccc", "ddd")); //存数组
print_r($mem->get("myarr"));
echo '<br>';
class Person {
var $name="zhangsan";
var $age=10;
}
$mem->add("myobj", new Person); //存对象
var_dump($mem->get("myobj"));
echo "<br>";
echo $mem->getVersion();//获取memcache的版本
.........................................................