Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Garbage collection sucks or is it just me?
    text
    copied!<p>I have the function below which I call very frequently in a loop.</p> <p>I waited 5 minutes as the memory climbed up from 1MB to 156MB. Should't PHP's garabage collector turn up and reduce this at some point?!</p> <p>Is it because I have set memory limit at 256MB?</p> <p>At echo point 2,3,4 its pretty constant memory usage. It goes down my half a meg at point 4. But point 1 is where the main memory increase happens. Probably because of <code>file_get_html</code> loading the html file in memory. </p> <p>I though the clear and unset of the variable <code>$html</code> would take care of this?</p> <pre><code>function get_stuff($link, $category ){ $html = file_get_html(trim("$link")); $article = $html-&gt;find('div[class=searchresultsWidget]', 0); echo '1 - &gt; '.convert(memory_get_usage(true)).'&lt;br /&gt;'; foreach($article-&gt;find('h4 a') as $link){ $next_url = 'http://new.mysite.com'.$link-&gt;href; $font_name = trim($link-&gt;plaintext); $html = file_get_html(trim("$next_url")); $article = $html-&gt;find('form[class=addtags]', 0); $font_tags = ''; foreach($article-&gt;find('ul[class=everyone_tags] li a span') as $link){ $font_tags .= trim($link-&gt;innertext).','; } echo '2 - &gt; '.convert(memory_get_usage(true)).'&lt;br /&gt;'; $font_name = mysql_real_escape_string($font_name); $category = mysql_real_escape_string($category); $font_tags = mysql_real_escape_string($font_tags); $sql = "INSERT INTO tag_data (font_name, category, tags) VALUES ('$font_name', '$category', '$font_tags')"; unset($font_tags); unset($font_name); unset($category); $html-&gt;clear(); mysql_query($sql); unset($sql); echo '3 - &gt; '.convert(memory_get_usage(true)).'&lt;br /&gt;'; } unset($next_url); unset($link); $html-&gt;clear(); unset($html); unset($article); echo '4 - &gt; '.convert(memory_get_usage(true)).'&lt;br /&gt;'; } </code></pre> <p>As you can see, I attempted to make use of unset feebly. Although its no good as I understand it won't "unset" memory as soon as I call it.</p> <p>Thanks all for any help on how I can reduce this upward rise of memory.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload