I tried to check memory consumption for large XML files (over 1GB) by loading them into DOMDocument (Win/CLI PHP 8.0.3).
I've noticed that memory used by process increases rapidly while loading file the file:
$dom = new DOMDocument();
$dom->load($path);
Process used ca. 3GB of memory for a 1GB XML file. Memory limit for PHP was set to 128M. Moreover PHP did not reported almost any memory usage (memory_get_usage
: 152 bytes for declared and 0 bytes for real). After performig XPath query memory showed by PHP rised by 32MB.
I observed similar behaviour with SimpleXMLElement
and even on Apache/PHP.
It looks like DOMDocument and SimpleXMLElement uses some external memory included to memory used by process but not by PHP. When I tried with 4GB XML I touched the limit of my phisical memory (16GB) but process did not crashed.
Does anybody know why it is going like that and what memory is used during loading XML? (or maybe you know how to control it...)