Fatal error: Allowed memory size of 268435456 bytes exhausted.
I have installed PHP 5.3 version and have added gc_collect_cycles();
where needed.
I am working with PHP simple dom library with good number of URLs (websites) to check them whether they are good (it checks for iframe and embed tags in the HTML, if there are iframe or embed tags with SRC atrribute different than youtube,metacafe or dailymotion will flag the URL as NOT good.
Websites are mine (not scraping anyone).
Why there is memory leak if clear() method, null, unset and gc_collect_cycles is called everytime at the end of the loop.
foreach ($data as $blog) {
$htm = file_get_html($blog['blogurl']);
if ($htm->find('iframe', 0)) {
foreach ($htm->find('iframe') as $if) {
if (! preg_match('/(dailymotion\.com|metacafe\.com|youtube\.com)/i', @ $if->src)) {
//this URL i
mark_url_not_good($blog['blogurl']);
$htm->clear();
$htm = null;
unset($htm);
gc_collect_cycles();
continue 2;
}
}
}
$htm->clear();
$htm = null;
unset($htm);
gc_collect_cycles();
}
Well, there might be just a memory leak inside the simple dom library, garbage collection won’t fix that. Without seeing your code, it’s hard to give suggestions what’s best to do in this situation.
You might want to replace the scrape functionality with a more native parser like
DOMDocument.