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?
Based on @Tak answer and @FrancisAvila comment, I found that this snippet works better for me:
while (true)
{
$dom = new DOMDocument();
if (libxml_use_internal_errors(true) === true) // previous setting was true?
{
libxml_clear_errors();
}
$dom->loadHTML(file_get_contents('ebay.html'));
}
print_r(libxml_get_errors()); // errors from the last iteration are accessible
This has the added benefits of 1) not discarding the errors of the last parse if you ever need to access them via libxml_get_errors(), and 2) calling libxml_clear_errors() only when necessary, since libxml_use_internal_errors() returns the previous setting state.