I'm trying to use PHP Simple HTML Dom Parser to parse some information from some sites. Does not matter what and where. But it seems, that there is some HUGE memory problem with it. I managed to cut the html code to only 6kB, but script that finds some elements and saves them to database takes even 700MB of ram and over 1GB of virtual memory! I read somewhere that I should use ->clear() to free up some memory, but seems that this is not the case.
I use str_get_html() once and 5 times using ->find() assigning the result to variable.
$main_html = str_get_html($main_site);
$x = $main_html->find(...);
$y = $main_html->find(...);
etc.
I tried to use for example $y->clear() after using $y but I get an error PHP Fatal error: Call to a member function clear() on a non-object even tho $y does exist and if($y) is true. Even foreach($y) echo $y->plaintext does return plaintext of $y.
From htop:
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
8839 username 20 0 1068M 638M 268 R 23.0 8.0 0:08.41 php myscript.php
What is wrong?
Simple test:
echo "(MEM:".memory_get_usage()."->";
$product = $p->find('a',0)->href;
echo memory_get_usage()."->";
unset($product);
$p->clear();
unset($p);
echo memory_get_usage().")";
The result is:
(MEM:11865648->11866192->11865936)
More readable form:
11865648->
11866192-> (+544 in total)
11865936 (+288 in total)
Of course I can't use $product->clear() as it says that PHP Fatal error: Call to a member function clear() on a non-object