dongle2627 2014-01-17 14:54
浏览 174

SIMPLE HTML DOM内存泄漏

I have a script using simple_html_dom.

foreach ($urls as $url)
    {
       $html = file_get_html($url);

        if($html->innertext!=''){

            foreach($html->find('.doc div[style="padding-top:1px;border-bottom:1px solid #eaeaec;padding-bottom:6px;"]') as $b){
                $b->style='""';
                echo $b;
            }           
            }
        $html->clear();
        unset($html); 
    }

When I running this script I get the following error:

Fatal error: Allowed memory size of 444596224 bytes exhausted (tried to allocate 1272 bytes).

  • 写回答

3条回答 默认 最新

  • douningle7944 2014-02-09 14:25
    关注

    if you still want to parse this file

    you can set your php.ini's memory_limit higher or use below code.

    ini_set('memory_limit', '128M');

    or optimize your code : (when found that, release it)

        $finder = $html->find('.doc div[style="..."]');
    
        foreach($finder as $index => $b){
            /* do something here */
            $finder[$index]->clear();
        }
        $html->clear();
    

    maybe you can use REGEX remove or get what you need

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失