当使用simple_html_dom从远程站点读取内容时,Php foreach循环意外结束

I have this code:

$target_url = "http://mysiteexmpl.com/";
$html = new simple_html_dom();
$html->load_file($target_url);

//here I find specific links and start looping each
foreach($html->find('a.link') as $link){
$newtarget_url = $link->href;

//here I open each url that I find as new
$newhtml = new simple_html_dom();
$newhtml->load_file($newtarget_url);

//getting price
foreach($newhtml->find('div.pprice') as $price){
$price=preg_replace("/[^0-9.]/", "",$price);echo '<br>';
}

//getting other info and so on
foreach($newhtml->find('div.prohead > h1') as $title){
$title= $title->innertext;echo '<br>';
}

//here I execute several queries and copying images from remote site to mine
}

The problem is that my target url-s are 21 if I echo $newtarget_url and dont execute queries, but when execute the full code and queries loop stops on the 7-th url and dont loop over all 21 url-s that it is supposed to loop Is this a memory leak problem or something else? How to debug it? How can the code above be optimized?

Thank you in avance for your time