Quote:
Originally Posted by mindstormmaster
It looks like there's some code missing. What you have there doesn't store anything back to Memcached, making it irrelevant in this example. Your comments are great, but could you post the complete script?
|
here is my original code:
PHP Code:
<?php
function get_steam_stats($id){
$mc=new Memcache;
if (!$mc->connect('localhost', 11211)) return false;
$ret=$mc->get('xd'.$id);
if (!$ret){
$data=file_get_contents("http://steamcommunity.com/profiles/".$id);
$ret=array();
if (strpos($data,'<h2>Private Profile</h2>')!==false) {
$ret['private']=1;
}else{
if (strpos($data,'status_online.gif')!==false){
$ret['online']=1;
}else if (($p1=strpos($data,'<p id="statusInGameText">'))!==false){
$p2=strpos($data,'<',$p1+25);
$tmp=substr($data,$p1+25,$p2-$p1-25);
$ret['ingame']=$tmp;
$ret['join']='steam://friends/joingame/'.$id;
}else{
if (($p1=strpos($data,'<p id="statusOfflineText">'))!==false){
$p2=strpos($data,'<',$p1+26);
$tmp=substr($data,$p1+26,$p2-$p1-26);
$ret['offline']=$tmp;
}
}
if (($p1=strpos($data,'<div class="avatarFull">'))!==false){
$p1=strpos($data,'<',$p1+24);
$p2=strpos($data,'>',$p1+1);
$tmp=substr($data,$p1,$p2-$p1+1);
$link_full=get_link_src($tmp);
gaben_downloadz0r($link_full,'/home/lol/public_html/avatars/lol_full'.$id.'.jpg');
$ret['img_full']=$tmp;
$tmp=str_replace('_full','',$tmp);
$link_small=get_link_src($tmp);
gaben_downloadz0r($link_small,'/home/lol/public_html/avatars/lol_small'.$id.'.jpg');
$ret['img_small']=$tmp;
}
if (($p1=strpos($data,'Steam Rating:</div>'))!==false){
$p2=strpos($data,'<',$p1+19);
$tmp=substr($data,$p1+19,$p2-$p1-19);
$ret['rating']=trim($tmp);
}
if (($p1=strpos($data,'Member since:</div>'))!==false){
$p2=strpos($data,'<',$p1+19);
$tmp=substr($data,$p1+19,$p2-$p1-19);
$ret['member']=trim($tmp);
}
if (($p1=strpos($data,'Playing time:</div>'))!==false){
$p2=strpos($data,'<',$p1+19);
$tmp=substr($data,$p1+19,$p2-$p1-19);
$ret['time']=trim($tmp);
}
}
$mc->set('xd'.$id,$ret,MEMCACHE_COMPRESSED,1800);
}
return $ret;
}
function get_link_src($data){
$p1=strpos($data,chr(34));
$p2=strpos($data,chr(34),$p1+1);
return substr($data,$p1+1,$p2-$p1-1);
}
function gaben_downloadz0r ($url,$target){
$data=file_get_contents($url);
if ($data) {
file_put_contents($target,$data);
}
}
?>
__________________