Chinaunix

标题: 利用php获取memcache的运行状态 [打印本页]

作者: expert1    时间: 2011-12-22 08:54
标题: 利用php获取memcache的运行状态
断断续续的看几天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看一下。
 
看来php和python在OOP上还是有区别的,python生成一个对象只需要:
 
newobject=classname() #可能需要传递参数
newobject.method      #调用方法。





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2