Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1060034
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: 系统运维

2011-08-12 15:20:18

断断续续的看几天php,借着其他语言基础,写了个memcache状态抓取代码
  1. <?php
  2. $mem =new Memcache; #new关键字生成一个对象
  3. $mem->connect("127.0.0.1",11211); #->调用类方法
  4. $status=$mem->getstats();
  5. foreach($status as $key=>$value)
  6. print "$key $value\n";
  7. $mem->close();
  8. ?>
没想到memcache在php里被当做Class了,用new生成一个对象,调用connect方法连接Memcached server,然后getstatus得到状态,最后foreach打印arrry,结果如下:(看来这个memcache很闲啊,几乎什么都没做)
pid  27890
uptime  4222
time  1313133923
version  1.4.6
libevent  2.0.12-stable
pointer_size  64
rusage_user  0.001999
rusage_system  0.006998
curr_connections  5
total_connections  20
connection_structures  6
cmd_get  15
cmd_set  15
cmd_flush  0
get_hits  15
get_misses  0
delete_misses  0
delete_hits  0
incr_misses  0
incr_hits  0
decr_misses  0
decr_hits  0
cas_misses  0
cas_hits  0
cas_badval  0
auth_cmds  0
auth_errors  0
bytes_read  683
bytes_written  11330
limit_maxbytes  134217728
accepting_conns  1
listen_disabled_num  0
threads  4
conn_yields  0
bytes  80
curr_items  1
total_items  15
evictions  0
reclaimed  7
要了解memcache相关的类和函数,还得$path/bin/php --re memcache看一下。
 p.s ,memcached数据放在memory里面,一旦重启自然丢失,别忘了它只是cache而已,此外它采用LRU(lease recently used)算法淘汰数据。单台服务器没必要用,因为db/memcached共用resource, 而且网络连接还要额外开销,没有任何意义:)

看来php和python在OOP上还是有区别的,python生成一个对象只需要:
 
newobject=classname() #可能需要传递参数
newobject.method      #调用方法。
阅读(3746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~