You are here:  » Problem with time to load


Problem with time to load

Submitted by rubenxela on Tue, 2010-02-16 17:44 in

This time I think that my code is ok, in fact I've a problem with the time to parse with a basic piece of code and would like you to tell me if you think that's normal.

In my XML file (500 items) I want to pick 1 item with reference XXXX, so with a php script called basically like article.php?ref=XXXX
For many functions Magicparser is fast but here it need 10 seconds for this basic thing !

I tried also to do it with a basic function with @simplexml_load_file and it's very quick, but I would like to use Magicparser for the whole site.

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
// This is my only condition
if ($record["CBIEN"]<>$_GET['ref']) return; 
// This is for meta tag, It's also very long if I put my tags before the script
print "<title>".$record["BIENDESC/LTITRE"]." ".$_GET['num']."Ifergane Immobilier</title> \n";
print 
"<script type=\"text/javascript\" src=\"js/jquery-1.2.6.min.js\"></script> \n";
print 
"<script type=\"text/javascript\" src=\"js/thickbox.js\"></script> \n";
print 
"<link rel=\"stylesheet\" href=\"css/thickbox.css\" type=\"text/css\" media=\"screen\" /> \n";
print 
"</head> \n";
print
" <body> \n";
print 
"<div style=\"width:800px\"> \n";
// Transform prices
$number $record["MPRIXEURO"];
$nombre number_format($number,  0' '' ');
$numberfrf $number*6.55957;
$nombrefrf number_format($numberfrf,  0' '' ');
// Pictures function
   
$photo $record["SFILENAMEPHOTO1"];
   if(
$photo==''){
$photo1='images/sansphoto.png';
$photo2 ="images/sansindex.png";
}
else {
     
$photo1 "reduc/".$record["SFILENAMEPHOTO1"]."";
 
$photo2 "photo/".$record["SFILENAMEPHOTO1"]."";
}
// NAME OF ITEM
print "<h1>".$record["BIENDESC/LTITRE"]."</h1> \n";
//INFORMATIONS
print "<strong>PRIX :</strong> ".$nombre." euros <small>(<i>".$nombrefrf." FRF</i>)</small> \n";
print  
"<br /> \n";
print 
"<small><strong>Référence du bien : ".$record["CBIEN"]."</strong></small><br /><br /> \n\n";
//PICTURES GALLERY
 
print "<img src=\"".$photo2."\" border=\"0\" style=\"float:left; margin-right:20px; \"> <br /><br />\n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@1"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@1"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@2"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@2"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@3"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@3"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@4"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@4"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<br /><br /> \n\n";
//DESCRIPTION
echo "<br /><br /<div style=\"border:1px solid black; padding:20px\"> \n\n";
echo 
"".$record["BIENDESC/LHTML"]."";
echo 
"</div>\n\n";
  }
  
MagicParser_parse("myfile.xml","myRecordHandler","xml|BACKSLASH/BIEN/");
?>

Submitted by support on Wed, 2010-02-17 10:36

Hi,

Make sure to return TRUE; at the end of myRecordHandler() if you are only interested in one record (condition) and this will stop the parser as soon as the record has been displayed..

Hope this helps!
Cheers,
David

Submitted by rubenxela on Wed, 2010-02-17 10:57

I don't realy understund.
This line is not enough ?
if ($record["CBIEN"]<>$_GET['ref']) return;

Submitted by support on Wed, 2010-02-17 11:02

Hi,

That line keeps it going to the record you are interested in; but then you can stop the parser after that by returning TRUE from myRecordHandler() - here it is in your code:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
// This is my only condition
if ($record["CBIEN"]<>$_GET['ref']) return;
// This is for meta tag, It's also very long if I put my tags before the script
print "<title>".$record["BIENDESC/LTITRE"]." ".$_GET['num']."Ifergane Immobilier</title> \n";
print 
"<script type=\"text/javascript\" src=\"js/jquery-1.2.6.min.js\"></script> \n";
print 
"<script type=\"text/javascript\" src=\"js/thickbox.js\"></script> \n";
print 
"<link rel=\"stylesheet\" href=\"css/thickbox.css\" type=\"text/css\" media=\"screen\" /> \n";
print 
"</head> \n";
print
" <body> \n";
print 
"<div style=\"width:800px\"> \n";
// Transform prices
$number $record["MPRIXEURO"];
$nombre number_format($number,  0' '' ');
$numberfrf $number*6.55957;
$nombrefrf number_format($numberfrf,  0' '' ');
// Pictures function
   
$photo $record["SFILENAMEPHOTO1"];
   if(
$photo==''){
$photo1='images/sansphoto.png';
$photo2 ="images/sansindex.png";
}
else {
     
$photo1 "reduc/".$record["SFILENAMEPHOTO1"]."";
 
$photo2 "photo/".$record["SFILENAMEPHOTO1"]."";
}
// NAME OF ITEM
print "<h1>".$record["BIENDESC/LTITRE"]."</h1> \n";
//INFORMATIONS
print "<strong>PRIX :</strong> ".$nombre." euros <small>(<i>".$nombrefrf." FRF</i>)</small> \n";
print  
"<br /> \n";
print 
"<small><strong>Référence du bien : ".$record["CBIEN"]."</strong></small><br /><br /> \n\n";
//PICTURES GALLERY
 
print "<img src=\"".$photo2."\" border=\"0\" style=\"float:left; margin-right:20px; \"> <br /><br />\n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@1"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@1"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@2"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@2"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@3"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@3"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<a href=\"http://ifergane.activimmo.fr/photo/".$record["PHOTO/SFILENAME@4"]."\" title=\"".$record["BIENDESC/LTITRE"]." ".$record["BIENDESC/LREGION"]."\" class=\"thickbox\"><img src=\"http://ifergane.activimmo.fr/reduc/".$record["PHOTO/SFILENAME@4"]."\" border=\"0\" height=\"100px\"></a> \n";
print 
"<br /><br /> \n\n";
//DESCRIPTION
echo "<br /><br /<div style=\"border:1px solid black; padding:20px\"> \n\n";
echo 
"".$record["BIENDESC/LHTML"]."";
echo 
"</div>\n\n";
return 
TRUE;
  }
  
MagicParser_parse("myfile.xml","myRecordHandler","xml|BACKSLASH/BIEN/");
?>

Cheers,
David.

Submitted by rubenxela on Wed, 2010-02-17 11:28

wow that's great, less than 1 second now ! Thank you David !