DOMDocument PHP Memory Leak
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:
<?php
libxml_use_internal_errors(true);
while(true){
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents('ebay.html'));
unset($dom);
libxml_use_internal_errors(false);
libxml_use_internal_errors(true);
echo memory_get_peak_usage(true) . "\r\n"; flush();
}
?>
PHP Simple HTML DOM Parser Memory Leak
See http://simplehtmldom.sourceforge.net/manual_faq.htm
Q: This script is leaking memory seriously... After it finished running, it's not cleaning up dom object properly from memory..
A: Due to php5 circular references memory leak, after creating DOM object, you must call dom->clear() to free memory if call file_get_dom() more then once.
Example:
$html = file_get_html(...); // do something...
$html->clear();
unset($html);
This happens a lot when you are using this library in a loop.
PHP memory leak of simple_html_dom (after the 'parse()' function)
You're not clearing the dom objects correctly, you forgot the parentheses:
$html->clear();
$images->clear();
Here's a demo of the corrected code
And here's the ouput:
Also, if you have any detected bug or possible patch, feel free to report it to their bugs/patch tracker
Related Topics
Mp4 Plays When Accessed Directly, But Not When Read Through PHP, on iOS
PHP - Create Simple Animated Gif from Two Jpeg Images
How to Upload Multiple Image in Laravel
HTML Form PHP Post to Self to Validate or Submit to New Page
Show Hide Div If, If Statement Is True
Laravel Error: Method Illuminate\View\View::_Tostring() Must Not Throw an Exception
Search and Replace Value in PHP Array
Remove Everything from the First Occurrence of a Character to the End of a String in PHP
Concat Columns with Laravel 5 Eloquent
Split an Array into N Arrays - PHP
Prevent Session Expired in PHP Session for Inactive User
Does PHP's $_Request Method Have a Security Problem
Preg_Replace with Array Replacements
Large Hex Values with PHP Hexdec