關於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);
}
相關文章
相關標籤/搜索