Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/01/2011, 09:28
orlandopc09
 
Fecha de Ingreso: julio-2010
Mensajes: 41
Antigüedad: 13 años, 9 meses
Puntos: 7
Pregunta Ayuda con rendimiento

Hola amigos
Estoy trabajando en un proyecto de e-Commerce en en el cual debo desarrollar un script php para importar los productos que llegan en un archivo xml a una bd en mysql. El principal problema que tengo es que en el xml llegan poco más de 32000 productos y el scrip tarda cerca de 1 hora en importarlos a la bd. Este es el código que lo hace, por favor si existe técnicas o mejoras en el código que mejore el rendimiento del script háganmelo saber.

Código PHP:
$xml_file 'products.xml';
if (
file_exists($xml_file)) {
    
$xml simplexml_load_file($xml_file);
} else {
    exit(
'Error al intentar abrir el fichero ' $xml_file);
}
$dbhost='localhost';
$dbusername='shop';
$dbuserpass='shop';
$dbname 'shop';
mysql_connect ($dbhost$dbusername$dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
/* Recorremos el XML */
$count 0;
foreach (
$xml->Product as $product) {
    
$Id=htmlentities(mysql_real_escape_string($product->Id), ENT_QUOTES);
    
$CategoryId=htmlentities(mysql_real_escape_string($product->CategoryId), ENT_QUOTES);
    
$CategoryName htmlentities(mysql_real_escape_string($product->CategoryName), ENT_QUOTES);
    
$Title=htmlentities(mysql_real_escape_string($product->Title), ENT_QUOTES);
    
$Brand=htmlentities(mysql_real_escape_string($product->Brand), ENT_QUOTES);
    
$PictureLocalFileName=htmlentities(mysql_real_escape_string($product->PictureLocalFileName), ENT_QUOTES);
    
$SKU htmlentities(mysql_real_escape_string($product->SKU), ENT_QUOTES);
    
$Price=htmlentities(mysql_real_escape_string($product->Price), ENT_QUOTES);
    
$PricePerUnit=htmlentities(mysql_real_escape_string($product->PricePerUnit), ENT_QUOTES);
    
$UnitName htmlentities(mysql_real_escape_string($product->UnitName), ENT_QUOTES);
    
$ShortDescription=htmlentities(mysql_real_escape_string($product->ShortDescription), ENT_QUOTES);
    
$Description=htmlentities(mysql_real_escape_string($product->Description), ENT_QUOTES);
    
$Nutrition htmlentities(mysql_real_escape_string($product->Nutrition), ENT_QUOTES);
    
$qry "INSERT INTO products(Id,CategoryId,CategoryName,Title,Brand,PictureLocalFileName,SKU,Price,PricePerUnit,UnitName,ShortDescription,Description,Nutrition) " .
            
" VALUES ('$Id', " .
            
"'$CategoryId', " .
            
"'$CategoryName', " .
            
"'$Title', " .
            
"'$Brand', " .
            
"'$PictureLocalFileName', " .
            
"'$SKU', " .
            
"'$Price', " .
            
"'$PricePerUnit', " .
            
"'$UnitName', " .
            
"'$ShortDescription', " .
            
"'$Description', " .
            
"'$Nutrition'" ")";
    
       
$result mysql_query($qry) or die(mysql_error());
       
   
$count++;
}
echo 
"<br/>";
echo 
"-------------------------------------------<br/>";
echo 
"Total de registros importados: $count properties<br/>";
echo 
"-------------------------------------------<br/>"