C
C
Creel2015-04-30 19:12:00
Python
Creel, 2015-04-30 19:12:00

How to close/unload XMLReader() data from memory?

There is a parser - here is a piece so that it is clear what needs to be unloaded

$strnSQL = "SELECT * FROM _posts";	
$rn = mysql_query($strnSQL);
while($rown = mysql_fetch_array($rn)){
  
    $nxml = new XMLReader();
    $nxml->open('../xml/import.xml'); // начинает нехватать памяти
      while($nxml->read() && $nxml->name !== 'offer');
        while($nxml->name === 'offer'){
          $n_node = new SimpleXMLElement($nxml->readOuterXML());
          $n_id = "" . $nxml->getAttribute("id");							

          $nxml->next('offer');
        }			
    $nxml->close();
    unset($nxml);
  }

the whole thing naturally has a lot of iterations and after a while the memory runs out.
I still don’t know how to work with memory normally and understand what kind of processes are going on there, but I feel that $nxml, although it overwrites itself, costs unset($nxml); but the memory is not freed.
How to make sure that on each circle the RAM that was occupied by an open file is completely reset?
The output is something like this but how to move to the beginning?
$rn = mysql_query($strnSQL);

    $nxml = new XMLReader();
    $nxml->open('../xml/import.xml');
    
while($rown = mysql_fetch_array($rn)){
  
      #$nxml->moveToFirstAttribute(); как заставить эту штуку работать чтоб чтение начиналось сначала 
      while($nxml->read() && $nxml->name !== 'offer');
        while($nxml->name === 'offer'){
          $n_node = new SimpleXMLElement($nxml->readOuterXML());
          $n_id = "" . $nxml->getAttribute("id");					

          $nxml->next('offer');
        }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander N++, 2015-05-01
@sanchezzzhak

I don't know why you need to navigate back if you need to read XML.
I XmlReader + SimpleXML read Yandex YML for 1-2GB.

F
Fortop, 2015-05-01
@Fortop

First you need to decide on who eats memory.
Therefore, we write an entry in the memory_get_usage () log at the end of each of the cycles, indicating for which cycle this information is.
Then, after the crash, we analyze the log and see who is leaking.

C
Creel, 2015-05-01
@80689248440

The solution lies in the fact that I return to the beginning of the document, since in
We go lower and lower, but I don’t know how to return the cursor to the beginning of the document except to open it again.
Tried:

moveToAttribute
moveToAttributeNo
moveToAttributeNs
moveToElement
moveToFirstAttribute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question