关于PHP Simple HTML DOM Parser的异常处理

1.关于PHP Simple HTML DOM Parser加载大页面报错

    加载大页面(好比:http://www.ebates.com/stores/all/index.htm)时,你调用其中的find的方法,报的错误信息是:Get Cssh back!PHP Fatal error:  Call to a member function find() on a non-object,缘由是你调用file_get_html($url);将永远返回false,由于它限制最大的页面大小为600000字节。解决办法是将simple_html_dom.php中define('MAX_FILE_SIZE', 600000);改成合适的大小。 php

2.内存溢出致使程序崩溃的问题 html

    若是是个大页面,而后你使用一个稍微复杂的选择器(多级选择器),就会跳出CLI中止工做的错误提示,而后程序就crash掉了。解决办法是(参考这里):将simple_html_dom.php中的clear函数由原来的 node

function clear()
{
    $this->dom = null;
    $this->nodes = null;
    $this->parent = null;
    $this->children = null;
}

替换成


function clear()
{
    unset($this->dom);
    unset($this->parent);
    unset($this->parent);
    unset($this->children);
}
相关文章
相关标签/搜索