我正在使用Simple HTML DOM来检索网站所有图像的所有网址,但在执行过程中我遇到内存使用错误,如何解决?
$count = 0;
$last = 1721;
include('simple_html_dom.php');
while ( $count <= $last) {
$html = file_get_html('http://myuri/?from='.$count);
// find all image inside post div
foreach($html->find('div.itemPost img') as $e) {
echo $e->src . '<br>';
}
}
这是错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in /home/peppo1616/public_html/script/simple_html_dom.php on line 1189
答案 0 :(得分:1)
在循环浏览img标记后调用析构函数,并将null
指定给$html
以清除一些内存。
while ( $count <= $last) {
$html = file_get_html('http://myuri/?from='.$count);
// find all image inside post div
foreach($html->find('div.itemPost img') as $e) {
echo $e->src . '<br>';
}
$html->clear();
$html = null;
}
在旁注中,我没有看到$count
的任何增量,你可能会以无限循环结束。