标签:
1 <?php 2 /** 3 * •Memcache::add — 增加一个条目到缓存服务器 4 * •Memcache::addServer — 向连接池中添加一个memcache服务器 5 * •Memcache::close — 关闭memcache连接 6 * •Memcache::delete — 从服务端删除一个元素 7 * •Memcache::get — 从服务端检回一个元素 8 * •Memcache::set — 在服务器上存储数据 9 * •Memcache::flush — 清洗(删除)已经存储的所有的元素 10 * •Memcache::getStats — 获取服务器统计信息 11 * •Memcache::pconnect — 打开一个到服务器的持久化连接 12 * •Memcache::replace — 替换已经存在的元素的值 13 * 使用MEMCACHE_COMPRESSED标记对数据进行压缩(使用zlib)。 14 * •Memcache::connect — 打开一个memcached服务端连接 15 * 同一个项目安装两次,key要有前缀 16 * memcache安全(不让别人访问) 17 * 内网,设置防火墙, 18 * Iptables -A INPUT -p tcp 192.168.1.111 -dport 11211 -j ACCEPT 19 * Iptables -A INPUT -p ucp 192.168.1.111 -dport 11211 -j ACCEPT 20 */ 21 $men=new Memcache; //实例化一个memcache类 22 //var_dump($men); // 返回一个对象 object(Memcache)[1] 23 $men->addServer(‘127.0.0.1‘,11211); 24 $men->add(‘mytest‘,‘today is tuesday‘); //往memcache中写入数据 25 $men->set(‘mytest‘,‘22today is tuesday‘); //覆盖掉了原来同名的键值 26 $str=$men->get(‘mytest‘); //从memcache中读出数据 27 $men->add(‘mytest2‘,‘today is tuesday喔喔‘); //往memcache中写入数据 28 $men->add(‘myarray‘,array(‘aaa‘,‘bbb‘,‘ccc‘,‘ddd‘)); 29 $rs2=$men->get(‘mytest2‘); 30 $rs4=$men->get(‘myarray‘); 31 echo $rs2; //today is tuesday喔喔 32 $men->replace(‘mytest2‘,‘today is tuesday喔喔2222‘); 33 $rs3=$men->get(‘mytest2‘); 34 echo $rs3; //today is tuesday喔喔2222 35 var_dump($rs4); 36 /** 37 * array (size=4) 38 0 => string ‘aaa‘ (length=3) 39 1 => string ‘bbb‘ (length=3) 40 2 => string ‘ccc‘ (length=3) 41 3 => string ‘ddd‘ (length=3) 42 */ 43 //echo $str; //today is tuesday 22today is tuesday 44 $rs=$men->getStats(); 45 //var_dump($rs); 46 /** 47 * array (size=20) 48 ‘pid‘ => string ‘1984‘ (length=4) 49 ‘uptime‘ => string ‘1474‘ (length=4) 50 ‘time‘ => string ‘1427158094‘ (length=10) 51 ‘version‘ => string ‘1.2.6‘ (length=5) 52 ‘pointer_size‘ => string ‘32‘ (length=2) 53 ‘curr_items‘ => string ‘2‘ (length=1) 54 ‘total_items‘ => string ‘15‘ (length=2) 55 ‘bytes‘ => string ‘153‘ (length=3) 56 ‘curr_connections‘ => string ‘4‘ (length=1) 57 ‘total_connections‘ => string ‘5‘ (length=1) 58 ‘connection_structures‘ => string ‘5‘ (length=1) 59 ‘cmd_get‘ => string ‘30‘ (length=2) 60 ‘cmd_set‘ => string ‘58‘ (length=2) 61 ‘get_hits‘ => string ‘30‘ (length=2) 62 ‘get_misses‘ => string ‘0‘ (length=1) 63 ‘evictions‘ => string ‘0‘ (length=1) 64 ‘bytes_read‘ => string ‘2697‘ (length=4) 65 ‘bytes_written‘ => string ‘3681‘ (length=4) 66 ‘limit_maxbytes‘ => string ‘67108864‘ (length=8) 67 ‘threads‘ => string ‘1‘ (length=1) 68 */ 69 70 class Person{ 71 var $name=‘zhangsan‘; 72 var $age=10; 73 } 74 $men->add(‘myobj‘,new Person); 75 $myobj=$men->get(‘myobj‘); 76 var_dump($myobj); 77 /** 78 * object(Person)[2] 79 public ‘name‘ => string ‘zhangsan‘ (length=8) 80 public ‘age‘ => int 10 81 */ 82 echo $men->getVersion(); //1.2.6 版本号 83 $men->close(); 84 ?>
标签:
原文地址:http://www.cnblogs.com/719907411hl/p/4505537.html