2015-09-19 87 views
1

在Windows 7,此使用的php.exe 5.2.17.17:避免浪费的存储器消耗

include_once('simple_html_dom.php'); 

function fix($setlink) 
{ 
    $setaddr = $setlink->href; 
    $filename="..\\".urldecode($setaddr); 
    $set=file_get_contents($filename); 
    $setstr = str_get_html($set); 
    // Do stuff requiring whole file 
    unset($set); 
    unset($setstr); 
} 

$setindexpath = "..\index.htm"; 
foreach(file_get_html($setindexpath)->find('a.setlink') as $setlink) 
{ 
    fix($setlink); 
} 

(依赖外部数据文件),因此失败:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in [snip]\simple_html_dom.php on line 620 

“功能修复” 是一个在这里回答类似问题的建议。 unset()是一厢情愿:-)

我该如何避免在未来的循环迭代中未使用的字符串继续消耗内存?没有玷污代码太多。同时提供整个文件作为字符串。

+0

我敢打赌DOMDocument会更高效.. – hanshenrik

回答