You are here:  » code to print faster feed?


code to print faster feed?

Submitted by keyesque2 on Tue, 2010-12-28 20:27 in

Is there a way to output a feed quicker/more efficiently than below?
Would doing this in a loop help (not sure how that might look)?
This will be on a trafficked page.

require("MagicParser.php");
$url = "http://feedsite.com...
  {
print "<a href='".$record["LINK"]." target='_blank' class=\"CH\">".$record["TITLE"]."</a>";
print "<br><strong>Business: </strong><font class=\"ct\">".$record["BUSINESS"]."</font>";
print "<br><strong>Location: </strong><font class=\"ct\">".$record["CITY"].", ".$record["STATE"]."</font>";
print "<p><div class=\"ct\">".$record["DESCRIPTION"]."</div></p>";
print "<hr align=\"center\" width=\"600\" size=2>";
  }
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

At times, I have noticed that the description on-up seems to get sort of sheared or randomly clipped across horizontally, presenting mere parts of characters with sections gone.

Submitted by support on Wed, 2010-12-29 09:27

Hi,

If this code is going to be on a high traffic page it would be best to cache
the XML response rather than request it every single page view. Not only
would this be much faster, but it would also reduce the load on the
remote server considerably.

I have described a simple but effective caching mechanism in the following
thread:

http://www.magicparser.com/node/136

With the writable cache/ directory, and cacheFetch() function added to your
code, the above section could then simply be replaced with:

  require("MagicParser.php");
  $url = "http://feedsite.com...
  function myRecordHandler($record)
  {
    print "<a href='".$record["LINK"]." target='_blank' class=\"CH\">".$record["TITLE"]."</a>";
    print "<br><strong>Business: </strong><font class=\"ct\">".$record["BUSINESS"]."</font>";
    print "<br><strong>Location: </strong><font class=\"ct\">".$record["CITY"].", ".$record["STATE"]."</font>";
    print "<p><div class=\"ct\">".$record["DESCRIPTION"]."</div></p>";
    print "<hr align=\"center\" width=\"600\" size=2>";
  }
  $xml = cacheFetch($url,3600);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

A cache value of 3600 as in the above would refresh the feed once every hour, the
parameter is in seconds.

Hope this helps!
Cheers,
David.
--
MagicParser.com

Submitted by keyesque2 on Fri, 2010-12-31 02:17

Thank you for the support, David.

I'm checking with the API/feed source for suggestions on the value setting (how often their updates come in)