您的位置:首页 > 编程语言 > PHP开发

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

2013-05-07 22:57 316 查看
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);改为合适的大小。

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

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

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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: