Hi

For a couple of years the code below has been working OK parsing an external XML feed and inserting data into a database. The size of the file has grown considerably since the date on which the script was written and I find an increasing amount of errors (PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: I/O warning : failed to load external entity) logged on the server.

I would like to ask for advice and assistance in updating what I have to hopefully improve its performance. The server that supplies the feed does seem to take a while to return any content, presumably it has to receive a request for the specific content for the user then render the XML and return it. In a browser it can take up to 10 seconds to do this even if the request is set to return just one set of results. I am guessing that this is the reason for the errors, the whole thing must time out before the feed is loaded into memory.

Your thoughts and examples would be welcomed.

regards

Colin

PHP Code:
<?php

ini_set
('display_errors'1);
ini_set('log_errors'1);
ini_set('error_log'dirname(__FILE__) . '/error_log.txt');
error_reporting(-1);

include (
'conn.php'); // Database connection AND URL for feed



try{
  
$feed = new SimpleXMLElement($xmlnulltrue);
}catch(
Exception $e){
  echo 
$e->getMessage();
  exit;
}

$sql 'INSERT INTO property (`id`, `date`, `ref`, `price`, `currency`, `price_freq`, `part_ownership`, `leasehold`, `type`, `country`, `town`, `province`, `beds`, `baths`, `pool`, `desc`) VALUES ';

foreach(
$feed->property as $property){
  
$sql .= sprintf(
    
//"\n(%d, '%s', '%s', %d),",
    
"\n(%d, '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%s'),",
   
$property->id,
   
mysql_real_escape_string($property->date),
   
mysql_real_escape_string($property->ref),
   
$property->price,
   
mysql_real_escape_string($property->currency),
   
mysql_real_escape_string($property->price_freq),
   
$property->part_ownership,
   
$property->leasehold,
   
mysql_real_escape_string($property->type->en),
   
mysql_real_escape_string($property->country),
   
mysql_real_escape_string($property->town),
   
mysql_real_escape_string($property->province),
   
$property->beds,
   
$property->baths,
   
$property->pool,
   
mysql_real_escape_string($property->desc->en)
  );
}

$sql rtrim($sql',') . ';';

echo 
$sql;

if(!
mysql_query($sql)){
  echo 
'<h1 style="color: red;">Error</h1><p>'mysql_error(), '<p>';
}
else
{
echo 
"Records have been inserted into the database";
}
?>