免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2658 | 回复: 0
打印 上一主题 下一主题

利用php获取memcache的运行状态 [复制链接]

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:54 |只看该作者 |倒序浏览
断断续续的看几天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      #调用方法。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP