php 查看memcache,利用php获取memcache的运行状态

断断续续的看几天php,借着其他语言基础,写了个memcache状态抓取代码

$mem =new Memcache; #new关键字生成一个对象

$mem->connect("127.0.0.1",11211); #->调用类方法

$status=$mem->getstats();

foreach($status as $key=>$value)

print "$key $value\n";

$mem->close();

?>

没想到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      #调用方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值