Answer the question
In order to leave comments, you need to log in
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);
}
$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
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.
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.
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 questionAsk a Question
731 491 924 answers to any question