PDA

View Full Version : مبتدی: rss reader مشکل ایجاد لود زیاد



irwebco
چهارشنبه 23 اسفند 1391, 14:16 عصر
سلام
از آشنایی با انجمن شما خوشحالم و امیدوارم بتونید برای رفع مشکلم کمک کنید من یک آر اس اس ریدر برای سایت ایجاد کردم اما مشکل دارم اونم ایجاد لود زیاد در گاهی اوقات مثلا گاهی پیش میاد وقتی از جی تی متریکس سایت رو چک میکنم تایم لود رو بالای 10 ثانیه میزنه و تمام زمان لود هم معتوف به همین rss reader هست
کاری که من کردم اینه که 3 تا فایل ایجاد کردم تو یکیش

<?php
$RSS_Content = array();

function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;

$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;

$tnl = $item->getElementsByTagName("pubDate");
$tnl = $tnl->item(0);
$date = $tnl->firstChild->textContent;

$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->textContent;

$y["title"] = $title;
$y["link"] = $link;
$y["date"] = $date;
$y["description"] = $description;
$y["type"] = $type;

return $y;
}


function RSS_Channel($channel)
{
global $RSS_Content;

$items = $channel->getElementsByTagName("item");

// Processing channel

$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);

// Processing articles

foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}

function RSS_Retrieve($url)
{
global $RSS_Content;

$doc = new DOMDocument();
$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
RSS_Channel($channel);
}

}


function RSS_RetrieveLinks($url)
{
global $RSS_Content;

$doc = new DOMDocument();
$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}

}

}

function Links($url, $size = 100)
{
global $RSS_Content;



RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size + 1);

foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$page .= "</br><a href=\"$link\">$title</a></br>\n";
}


return $page;

}
function Display($url, $size = 15, $site = 0, $withdate = 0)
{
global $RSS_Content;

$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;

RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, $site, $size + 1 - $site);

foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$page .= "<li><a href=\"$link\">$title</a>";
if($withdate)
{
$date = $article["date"];
$page .=' <span class="rssdate">'.$date.'</span>';
}
$description = $article["description"];
if($description != false)
{
$page .= "<br><span class='rssdesc'>$description</span>";
}
$page .= "</li>\n";

if($type==0)
{
$page .="</b><br />";
}

}

if($opened == true)
{
$page .="</ul>\n";
}
return $page."\n";

}
?>

و تو یکیش هم


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="alternate" type="application/rss+xml" title="عنوان" href="/announcementsrss.php"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">a,a:visited{color:#565656 ;text-decoration:none;}a:hover{color:#e5bd02;text-decoration:none;}body { direction:rtl;text-align:right;font:13px tahoma;color:#0000;width:242px;height:30px;padding :6px 6px 6px 6px;}</style>
</head><body><marquee direction="down" height="120px" scrollamount="2.5" onmouseover="this.stop();" onmouseout="this.start();" ><?php require_once("rsslib.php");echo links("http://site/announcementsrss.php", 4);?></marquee></body></html>


ممنون میشم اگر مشکلی توی این کدها میبینید که باعث بالارفتن لود میشه بهم بگید و اینم بگم من اصلا بنامه نویسی بلد نیستم
ممنون

irwebco
چهارشنبه 23 اسفند 1391, 23:59 عصر
یعنی کسی نمیدونه :-/

irwebco
پنج شنبه 24 اسفند 1391, 11:58 صبح
خیلی ممنون

irwebco
یک شنبه 27 اسفند 1391, 15:52 عصر
:متفکر: نکنه کلا این فروم تعطیله !؟ کسیم اینجا فعالیت داره !