当使用simple_html_dom从远程站点读取内容时,Php foreach循环意外结束
我有以下代码:当使用simple_html_dom从远程站点读取内容时,Php foreach循环意外结束,php,loops,foreach,Php,Loops,Foreach,我有以下代码: $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; //her
$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
}
$target\u url=”http://mysiteexmpl.com/";
$html=新的简单html\U dom();
$html->load_文件($target_url);
//在这里,我找到特定的链接并开始循环每个链接
foreach($html->find('a.link')作为$link){
$newtarget_url=$link->href;
//在这里,我打开我发现的每个新url
$newhtml=newsimple_html_dom();
$newhtml->load_文件($newtarget_url);
//获得价格
foreach($newhtml->find('div.pprice')作为$price){
$price=preg_replace(“/[^0-9.]/”,“,$price);echo“
”;
}
//获取其他信息等等
foreach($newhtml->find('div.prohead>h1')作为$title){
$title=$title->innertext;回显“
”;
}
//在这里,我执行几个查询并将图像从远程站点复制到我的站点
}
问题是,如果我回显$newtarget_url并且不执行查询,那么我的目标url-s是21,但是当执行完整代码和查询时,循环在第7个url上停止,并且不循环它应该循环的所有21个url-s
这是内存泄漏问题还是其他问题?如何调试它?如何优化上面的代码
非常感谢你抽出时间来好吧,没必要猜测会发生什么。错误日志文件说明了什么?它不能为空。至少服务器启动必须记录在那里。当出现mysql错误时,它是空的。很抱歉,一个特定的mysql错误导致循环停止。。这就是原因,真的很抱歉时间被偷了!非常感谢。