1

I have a problem, that when I try to load an XML-file (200MB), that I get the error-message:

simplexml_load_string(): Memory allocation failed

I tried it with smaller files (60 MB) and it works fine on them. I'm working on a windows-machine (+ xampp) if that is important. I already tried to use ini_set('memory_limit', '-1'); as well a 1024M as value. Could it be possible, that simplexml has a limit on how large the files can be?

I tried to look up this question on here, but the results are all concentrated on PHPExcel or similar.

PHP Warning: simplexml_load_string(): Memory allocation failed : building node in D:\xampp\htdocs\merger\index.php on line 11

while line 11 is simply:

$oldItems = simplexml_load_string($oldFile); // that's the 200MB file

I'm aware that there are probably smarter ways (like XSLT) to go for, but for now I'm stuck to simplexml. Any hints?

DasSaffe
  • 2,080
  • 1
  • 28
  • 67
  • Although it may be worth looking at https://stackoverflow.com/questions/911663/parsing-huge-xml-files-in-php to read large files. – Nigel Ren Mar 31 '20 at 12:30
  • _“Could it be possible, that simplexml has a limit on how large the files can be?”_ - then it would likely tell you so, with a different error message. Don’t assume this is merely about the input “file” resp. string size - this is much more about how much memory it needs internally, to keep all this data in the form of a SimpleXMLElement object instances, with all its properties etc. pp. – CBroe Mar 31 '20 at 12:31
  • I've re-opened this question and upvoted it. That is not the standard PHP "out of memory" error, which is something like "Memory limit of X bytes exhausted on line Y", so you are correct that raising the memory_limit setting is not the solution. My guess is that the error is coming from the libxml parser PHP uses internally. – IMSoP Apr 02 '20 at 14:44
  • One way to improve the question, though (remember to [edit] rather than adding comments or a new question) would be a way to reproduce the error. Obviously pasting 60MB of XML into the question isn't going to work, but is there a way we could build a file that exhibits the problem by repeating a smaller part lots of times? – IMSoP Apr 02 '20 at 14:48
  • Have you tried setting the `LIBXML_PARSEHUGE` flag? – Shankar Narayana Damodaran Aug 25 '21 at 11:49

0 Answers0