Running PHP 5.3.6 under MAMP on MAC, the memory usage increases every x calls (between 3 and 8) until the script dies from memory exhaustion. How do I fix this?
libxml_use_internal_errors(true);
while(true){
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents('http://www.ebay.com/'));
unset($dom);
echo memory_get_peak_usage(true) . '<br>'; flush();
}
Using
libxml_use_internal_errors(true);
suppresses error output but builds a continuous log of errors which is appended to on each loop. Either disable the internal logging and suppress PHP warnings, or clear the internal log on each loop iteration like this: