Is it possible to monitor the real memory consumption of a script?

Wrote a class which breaks the xml file in parts using xPath. On the LAN everything works out well - 25 minutes and 14 MB of memory (memory_get_usage()). I tried to run on the server - the process fell with such logs
Jan 20 10:00:41 184382 kernel: [5963135.639197] Out of memory: Kill process 1414 (php) score 809 or sacrifice child
Jan 20 10:00:41 184382 kernel: [5963135.641229] Killed process 1414 (php) total-vm:4209736kB, anon-rss:3692024kB, file-rss:0kB

The numbers are not even close. Is it possible to get real numbers or something else?
April 4th 20 at 12:58
2 answers
April 4th 20 at 13:00
in short:
This can't be fixed; PHP doesn't control the way libxml2 does the allocations.
April 4th 20 at 13:02

Find more questions by tags PHP