title: parsing xml and insert data in mysql table
body: <p>I am parsing an xml file using php simplexml_load_file() and then inserting the desired data in a mysql ISAM table. The problem is that the code works "most" of the times, with 500 internal server errors here and there. The XML file that I am trying to process is big (around 50 MB), and it yields around 25000 rows in the mysql table when it works. When I get the error, the script inserts anything from a few rows to a few thousand rows.</p>
  
  <p>Anyway, here is the code, I would appreciate it if someone has any insight into this, or has an alternative way, I don't know, maybe batch processing or something like that.</p>
  
  <pre><code>&lt;?php
  include ("myconnection.php");
  
  mysql_query("DELETE FROM mytable") or die(mysql_error());   
  
  echo "data deleted, now insert: &lt;br /&gt;&lt;br /&gt;";
  
  //the url for the feed:
  $feed = 'cachy/copy.xml';
  
  
  echo "myfeed: ".$feed;
  echo "&lt;br /&gt;";
  
  // Load the feed
  
  $xml = simplexml_load_file($feed);
  if ($xml != null)
  {
  echo "&lt;br /&gt;Success! feed available!&lt;br /&gt;&lt;br /&gt;";
  }
  else
  { 
  echo "&lt;br /&gt;Couldn't fetch the content&lt;br /&gt;&lt;br /&gt;";
  die;
  }
  
  //die;
  //ini_set("memory_limit","256M");
  //set_time_limit(120);
  
  
  function clean($input)
  {
     $input = trim($input);  
     $input = htmlentities($input, ENT_QUOTES);
     $input = mysql_escape_string($input);
     $input = EscapeShellCmd($input);
     return $input;  
  }
  
  
  //insert data from feed
  foreach($xml-&gt;xpath('//product') as $products)
  
  {
  
  $product_name = clean($products-&gt;product_name);
  
  mysql_unbuffered_query("INSERT INTO mytable (onsaledate, onsaletime, eventdate, eventtime, buyat_short_deeplink_url, product_name, level1, level2, VenueName, VenueDMAID)VALUES (\"$products-&gt;OnsaleDate\",\"$products-&gt;OnsaleTime\",\"$products-&gt;EventDate\",\"$products-&gt;EventTime\",\"$products-&gt;buyat_short_deeplink_url\",\"$product_name\",\"$products-&gt;level1\",\"$products-&gt;level2\",\"$products-&gt;VenueName\",\"$products-&gt;VenueDMAID\")") or die(mysql_error());
  
  
  }
  
  mysql_close($myConnection);  
  
  echo "records inserted my man!";  
  
  die;
  </code></pre>
  
  <p>Thanks in advance for your help!</p>