public function cldata(){ $memcache_obj = new Memcache; $memcache_obj->connect('127.0.0.1', '11211'); $all_items = $memcache_obj->getExtendedStats('items'); foreach($all_items as $option=>$vall){ if (isset($all_items[$option]['items'])) { $items = $all_items[$option]['items']; foreach ($items as $number => $item) { $str = $memcache_obj->getExtendedStats('cachedump', $number, 0); $line = $str[$option]; if(is_array($line) && count($line) > 0){ foreach($line as $key => $value) { $keys[] = $key; } } } } } dump(count($keys));//获取到key if(count($keys)>50){//要写入的数据条数 $end=50; }else{ $end=count($keys); } for($i=0;$i<=$end;$i++){ if(!strstr($keys[$i],'datadb')) continue; $ksv = str_replace('datadb','',$keys[$i]); /*$logdata = unserialize(S('login'.$ksv));//登录写入 if(is_array($logdata)){ $this->addsuidinlogin($logdata[0],$logdata[1],$logdata[2],1); } */ /*$sdata = unserialize(S('regadd'.$ksv));//注册写入 if(is_array($sdata)){ $this->baiduad($sdata[0],$sdata[1],$sdata[2],$sdata[3],$sdata[4],1); } */ $regdata = unserialize(S('datadb'.$ksv)); $ress[]=$regdata; S('datadb'.$ksv,null); } $addb = M()->db(66,C('DB_WEB_AD'));//批量写入 addall $addb->table('mj_ad_count')->addall($ress); echo M()->getLastSql(); }
希望本文所述对大家的php程序设计有所帮助。