Got another fun one for you all today.
I have working code that pulls from various RSS feeds and orders them by which of them has most recent pubdate.
The issues I have is that it is slow. It slows down the loading of the site. Not only that, because it's all hosted server side, it slows down the response if multiple people are accessing the site simultaneously.
So, I'd like to convert this into either a JavaScript function, which would then fill the tag's innerHTML to what's pulled back from the database or another option that I would love for anyone to suggest (If it's faster).
Without further adieu: The Code:
PHP
function RSSFeeder() {
$client = buildCon();
//Query removed, simply gets the RSS URL from the database
$query = "";
$result = $client ->run($query);
$RSSList = array();
foreach($result ->getRecords() as $record)
{
$ComicArray = array();
$ComicName = $record ->value('Name');
$RSS = $record ->value('RSS');
$URL = $record ->value('URL');
$content = file_get_contents($RSS);
$x = new SimpleXmlElement($content);
for ($i = 0; $i < 1; $i++) {
$profile = $x ->channel ->item[$i];
$pubDate = $profile ->{ "pubDate"};
}
$ComicArray['URL'] = $URL;
$ComicArray['Comic'] = $ComicName;
$ComicArray['pubDate'] = $pubDate;
$RSSList[] = $ComicArray;
}
#usort($RSSList, "sortFunction");
usort($RSSList, "compareRSSTimes");
return $RSSList;
}
At the end, you probably saw the usort method, so here it is:
function compareRSSTimes($a, $b) {
$a = strtotime($a['pubDate']);
$b = strtotime($b['pubDate']);
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
From there, the array is sent back to a PHP script that builds the output based on the chronological order of updates. It works fine. It just takes a little while to load the page and I'm worried about the sustainability of my terribad server if/when more users access the page.
Suggestions?