title: php memory limit 2000M exhausted
body: <p>Am trying to upload <strong>Do not call list</strong> xml file to MySql DB. The file size is 256MB. It gets uploaded but when its starts processing am looping the phone numbers and concatenating 1000 phone numbers in a variable. When it reaches the limit of 1000, am creating a INSERT query and executing the query. BUt the problem is after inserting 3,50,000 records it say <strong>"Fatal error: Allowed memory size of 2097152000 bytes exhausted (tried to allocate 24 bytes) in /var/domains/htdocs/aim/leads/dnc on line 1308)"</strong>. </p>
  
  <p>Below is the code snippet.</p>
  
  <pre><code>                    if(($fp = fopen($destination,"r"))) {
  
                          $buffer = fgets($fp);
                          $objXml = new XML($buffer);
                          $lists = Set::reverse($objXml);
  
                          $buffer = fgets($fp);
                          $objXml = new XML($buffer);
                          $acc = Set::reverse($objXml);
  
                          try {
                              while(!feof($fp)){
                                  $counter = 0;
                                  $phonesNo = "";
  
                                  while(!feof($fp) &amp;&amp; ($buffer = fgets($fp)) &amp;&amp; $counter != 1000){
  
                                      $objXml = "";
                                      $arrXml = "";
  
                                      $objXml = new XML($buffer);
  
                                      $arrXml = Set::reverse($objXml);
  
  
                                      $counter++;
                                      if(isset($arrXml['Ph']['val']))
                                          $phonesNo .= "(".$acc['Ac']['val'].$arrXml['Ph']['val']."),";
  
                                  }
  
                                  $phonesNo = substr($phonesNo,0,-1);
                                  $sql = "INSERT INTO do_not_call_lists (`phone`) VALUES " .$phonesNo;
  
                                  unset($phonesNo);
                                  $this-&gt;Lead-&gt;query($sql);
                              }
                          }catch (Exception $ex){
                              trigger_error("ERROR: ". $ex-&gt;getMessage(). "  Trace: ".$ex-&gt;getTrace());
                          }
  
                          $this-&gt;Session-&gt;setFlash('File imported successfully.','default',array('class'=&gt;'sucessMsg'));
  
                       }
  </code></pre>
  
  <p>Thanks a lot in advance.</p>