You are here:  » 15 seconds to render page


15 seconds to render page

Submitted by Adam M on Wed, 2008-09-17 00:08 in

Hi,
Thanks for a cool product and good docs, I am struggling with one problem slooooooow performance.

I am reading XML from a URL and displaying 3 records on a web page and it takes 15 (or more) seconds for the page to render.

Without the XML the page renders instantaneously.

Here's the code:

<?php
  header("Content-Type: text/html;charset=utf-8");
require("MagicParser.php");
  function myRecordHandler($deal)
  {
    echo "<h4>".$deal["HOTELNAME"]."</h4>";
    echo "<img src=' ".$deal["THUMBNAILURL"]." ' />";
    echo "<p>".$deal["PRICE" ]. "&nbsp;Per Night" , "</p>";
  }
$url ="{link saved}";
MagicParser_parse($url,"myRecordHandler","xml|deals/deal/");
?>

Submitted by support on Wed, 2008-09-17 08:32

Hello Adam,

I just ran a test fetching the URL independantly of Magic Parser, and the script took the same time to run; so in this instance it is presumably a delay in the production of the feed rather than your handling of it - and it is possible that the provide doesn't intend this feed to be used in "real time" - in other words you would normally request the feed as part of a CRON process and insert the data into a database for subsequent display.

Here's the test code I wrote (replace the URL with the correct URL of course):

<?php
  $url 
="{link saved}";
  
$fp fopen($url,"r");
  while(!
feof($fp)) $xml .= fread($fp,1024);
  
fclose($fp);
  print 
"Done.";
?>

As an alternative to using a database, another option is to cache the file locally, so you are only making a request to the remote server say, once per day. I've documented my preferred caching method in the following thread which may help:

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

Hope this helps,

Cheers,
David.