You are here:  » Reading a LARGE XML file into MySQL


Reading a LARGE XML file into MySQL

Submitted by mcatlett on Fri, 2007-01-19 16:13 in

Hello all,

I am new user to MagicParser and I must say this is a great product. It has solved every problem I have except for one. I need to read a large XML file into MySQL. The file is roughly 80MB and will most likly grow as time goes on. My script (below) will read in a large portion (about 17,000 products), but then it stops. Any advise would be great!

Thanks,

Mike

<?php
  require("MagicParser.php");
  $filename = "all.xml";
   include '../library/config.php';
include '../library/opendb.php';
  function myRecordHandler($product)
  {
  $sql = "
      INSERT INTO test SET
programname = '".mysql_real_escape_string( $product["PROGRAMNAME"] )."',
programurl = '".mysql_real_escape_string( $product["PROGRAMURL"] )."',
lastupdated = '".mysql_real_escape_string( $product["LASTUPDATED"] )."',
name = '".mysql_real_escape_string( $product["NAME"] )."',
keywords = '".mysql_real_escape_string( $product["KEYWORDS"] )."',
description = '".mysql_real_escape_string( $product["DESCRIPTION"] )."',
sku = '".mysql_real_escape_string( $product["SKU"] )."',
manufacturer = '".mysql_real_escape_string( $product["MANUFACTURER"] )."',
manufacturerid = '".mysql_real_escape_string( $product["MANUFACTURERID"] )."',
currency = '".mysql_real_escape_string( $product["CURRENCY"] )."',
saleprice = '".mysql_real_escape_string( $product["SALEPRICE"] )."',
price = '".mysql_real_escape_string( $product["PRICE"] )."',
retailprice = '".mysql_real_escape_string( $product["RETAILPRICE"] )."',
buyurl = '".mysql_real_escape_string( $product["BUYURL"] )."',
impressionurl = '".mysql_real_escape_string( $product["IMPRESSIONURL"] )."',
imageurl = '".mysql_real_escape_string( $product["IMAGEURL"] )."',
advertisercategory = '".mysql_real_escape_string( $product["ADVERTISERCATEGORY"] )."',
special = '".mysql_real_escape_string( $product["SPECIAL"] )."',
instock = '".mysql_real_escape_string( $product["INSTOCK"] )."',
gift = '".mysql_real_escape_string( $product["GIFT"] )."',
condition = '".mysql_real_escape_string( $product["CONDITION"] )."',
        standardshippingcost = '".mysql_real_escape_string( $product["STANDARDSHIPPINGCOST"] )."'
      ";
  mysql_query($sql) or die(mysql_error());
  echo "Data Inserted!";
  }
  MagicParser_parse($filename,"myRecordHandler","xml|catalog/product/");
?>

Submitted by support on Fri, 2007-01-19 16:24

Hello Mike,

Very quickly, it may be a PHP timeout issue (the default is 30 seconds). You may be able to fix it by adding the following line to the top of your script:

  set_time_limit(0);

The value of zero will disable the time limit. You might also be interested in the advice regarding import timeouts for my Price Tapestry product (and uses Magic Parser), which can be found on the following page:

http://www.pricetapestry.com/node/582

Hope this helps,
Cheers,
David.