创建对象
$mem = new Memcache();
添加服务
$mem->addServer("192.168.150.250",11211);
$mem->addServer("192.168.150.138",11211);
$mem->addServer("192.168.112.128",11211);
放置信息
$mem->add("mystr","hello memcache!",MEMCACHE_COMPRESSED,0);
$mem->add("myarray",array(10,20,30,40),MEMCACHE_COMPRESSED,0);
$mem->add("myob",new Stu(),MEMCACHE_COMPRESSED,0);
获取信息
echo $mem->get("mystr")."
";
var_dump($mem->get('myarray'));
echo "
";
$mem->get("myob")->getinfo();
memcached服务器的安全防护
• 1. 内网访问
– memcached -d -m 1024 -u root –l 192.168.0.10 –p 11211 –c 1024 start
• 2. 设置防火墙
– iptables –F
– iptables –P INPUT DROP
– iptables –A INPUT –p tcp –s 192.168.0.10 –-dport 11211 –j ACCEPT
– iptables –A INPUT –p udp –s 192.168.0.10 –-dport 11211 –j ACCEPT
已有 0 条评论